jQuery Tutorial
html() method is used to get the HTML contents of the first element in the set of matched elements or set the HTML contents of every matched HTML element.
.html() // to get the html contents.
<html> <head> <title>The jQuery Example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script type = "text/javascript"> $(document).ready(function(){ alert( $('.codingpointer').html()); }); </script> </head> <body> <p>Test Section</p> <div> <div class="codingpointer">Hello</div> <div class="codingpointer">Goodbye</div> </div> </body> </html>Output:
.html(html string) // to set the html contents.
<html> <head> <title>The jQuery Example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script type = "text/javascript"> $(document).ready(function(){ $("p").html("Welcome to jQuery!"); }); </script> </head> <body> <p>Test Section</p> <div> <div class="codingpointer">Hello</div> <div class="codingpointer">Goodbye</div> </div> </body> </html>Output:
here setting html element content using another html element contents.Welcome to jQuery!
HelloGoodbye
<html> <head> <title>The jQuery Example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script type = "text/javascript"> $(document).ready(function(){ $("p").html( $('.codingpointer').html()); }); </script> </head> <body> <p>Test Section</p> <div> <div class="codingpointer">Hello</div> <div class="codingpointer">Goodbye</div> </div> </body> </html>Output:
Hello
HelloGoodbye
jQuery Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page