Home
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function () { $("#btn1").click(function () { $(".myCls").html('<p style="color: red">This is a paragraph - added using html()</p>'); }); $("#btn2").click(function () { var h1 = $('h1').html(); alert("Reading h1 tag: " + h1); }); }); </script> </head> <body> <h1>jQuery Manipulation Methods: html()</h1> <div class="myCls"> </div> <button id="btn1">Click Me to set contents using .html()</button> <button id="btn2">Click Me to get contents using .html()</button> </body> </html>
Result: