jQuery text() Method | jquery change html text
❮jQueryHTML/CSSMethods[1]ExampleSettextcontentforall
elements:$("button").click(function(){ $("p").text("Helloworld!");});TryitYourself»[2]DefinitionandUsageThetext()methodsetsorreturnsthetextcontentoftheselectedelements.Whenthismethodisusedtoreturncontent,itreturnsthetextcontentofallmatchedelements(HTMLmarkupwillberemoved).Whenthismethodisusedtosetcontent,itoverwritesthecontentofALLmatchedelements.Tip:TosetorreturntheinnerHTML(text+HTMLmarkup)oftheselectedelements,usethehtml()[3]met...
❮ jQuery HTML/CSS Methods[1]
ExampleSet text content for all <p> elements:
$("button").click(function(){ $("p").text("Hello world!");});
Try it Yourself »[2] Definition and UsageThe text() method sets or returns the text content of the selected elements.
When this method is used to return content, it returns the text content of all matched elements (HTML markup will be removed).
When this method is used to set content, it overwrites the content of ALL matched elements.
Tip: To set or return the innerHTML (text + HTML markup) of the selected elements, use the html()[3] method.
SyntaxReturn text content:
Set text content:
$(selector).text(content)
Set text content using a function:
$(selector).text(function(index,currentcontent))
Parameter Description content Required. Specifies the new text content for the selected elementsNote: Special characters will be en...