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

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


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


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



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

$("#btn").click(function() {
$("#p1").text("New Text.");

All contributors

Looking to contribute?

Learn JavaScript on Codecademy