JQuery html()
The .html()
method in jQuery is used to get or set the HTML content of the selected element.
Syntax
To get the HTML content of an element:
$(selector).html();
To set the HTML content of an element:
$(selector).html(htmlString);
Use
The .html()
method is useful for manipulating the content of an element. It can be used to get the current HTML content of an element, or to set new HTML content to the element.
Example
Here is an example of using the .html()
method to change the content of an element:
HTML:
<div id="myDiv">
<p>Hello, world!</p>
</div>
JavaScript:
$(document).ready(function(){
$("#myDiv").html("<p>Goodbye, world!</p>");
});