How to get and set HTML using jQuery html method

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.



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

<!DOCTYPE html>
    <div class="container">
        <div id="paragraph">
            <p>Hello Earth!</p>
    <script src=""></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>

I hope it will help you.