14

Get and Set HTML using jQuery html method

 2 years ago
source link: https://www.laravelcode.com/post/get-and-set-html-using-jquery-html-method
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Get and Set HTML using jQuery html method

  222 views

  7 months ago

jQuery

jQuery html() method allows you to get content from element or set new content to matched element. This also includes HTML tags. If no any element is matched, it returns undefined.

Syntax:

$(selector).html();

Here is the example below how you can get content and set new content to the element:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <div class="container">
        <div id="paragraph">
            <p>Hello Earth!</p>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script type="text/javascript">
        console.log($('#paragraph').html()); // <p>Hello Earth!</p>
        $('#paragraph').html('<p>Hello World!</p>');
        console.log($('#paragraph').html()); // <p>Hello World!</p>
    </script>
</body>
</html>

I hope it will help you.

Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK