Published Aug 4, 2022Updated Aug 4, 2022
Contribute to Docs

The .html() method gets or sets the contents of an HTML element.


Getting HTML, the .html() method is called without a parameter:


Setting HTML, the .html() method is called with a parameter containing the new HTML:



The following jQuery code will read and reset the HTML in #p1 when #btn is clicked:

$("#btn").click(function() {
$("#p1").html("<b>New Text.</b>");

All contributors

Looking to contribute?

Learn JavaScript on Codecademy