.text()
BrandonDusch580 total contributions
Published Aug 4, 2022Updated Aug 4, 2022
Contribute to Docs
The .text()
method gets or sets the text of an HTML element.
Syntax
Getting text, the .text()
method is called without a parameter:
$(selector).text();
Setting text, the .text()
method is called with a parameter containing the new text:
$(selector).text(newtext)
Example
The following jQuery code will read and reset the text in #p1
when #btn
is clicked:
$("#btn").click(function() {alert($("#p1").text());$("#p1").text("New Text.");});
All contributors
- BrandonDusch580 total contributions
- StevenSwiniarski474 total contributions
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.