jQuery html() Method | jquery out html
❮jQueryHTML/CSSMethods[1]ExampleChangethecontentofall
elements:$("button").click(function(){ $("p").html("Helloworld!");});TryitYourself»[2]DefinitionandUsageThehtml()methodsetsorreturnsthecontent(innerHTML)oftheselectedelements.Whenthismethodisusedtoreturncontent,itreturnsthecontentoftheFIRSTmatchedelement.Whenthismethodisusedtosetcontent,itoverwritesthecontentofALLmatchedelements.Tip:Tosetorreturnonlythetextcontentoftheselectedelements,usethetext()[3]method.Synt...
❮ jQuery HTML/CSS Methods[1]
ExampleChange the content of all <p> elements:
$("button").click(function(){ $("p").html("Hello <b>world</b>!");});
Try it Yourself »[2] Definition and UsageThe html() method sets or returns the content (innerHTML) of the selected elements.
When this method is used to return content, it returns the content of the FIRST matched element.
When this method is used to set content, it overwrites the content of ALL matched elements.
Tip: To set or return only the text content of the selected elements, use the text()[3] method.
SyntaxReturn content:
Set content:
$(selector).html(content)
Set content using a function:
$(selector).html(function(index,currentcontent))
Parameter Description content Required. Specifies the new content for the selected elements (can contain HTML tags) function(index,current...