This method is used to change the content of the elements . It change only selected elements .It can also replaces the selected content with new content.It doesn't take any arguments.
Syntax :
$(selector).html()
Return content :
$(selector).html(content) // It return the content of the all matched elements
Set Content :
$(selector).html(function(index, currentcontent)) // It is used to overwrites the content of all the matched elements
Example :
HTML Code :
<html>
<head></head>
<body>
<button>Click here to see the change of selected contents of matched elements</button>
<p>It will change after click on button</p>
</body>
</html>
jQuery Code :
$(funtion(){
$("button").click(function(){
$("p").html("Hello<b>Mukesh</b>")
});
});
Output :
Before jQuery :
It will change after click on button
After jQuery :
Hello Mukesh // Content of p has been changed
0 Comment(s)