Managing Content
Content is king
A few words about element content — we have 2 methods for working with it: html() and text(). There's one key difference between them — the first one can get and insert HTML code, while the second always operates with text. Even if you try to feed it HTML, you'll get text where the tags are converted to HTML entities:
$("section").text("Some <strong>text</strong>");
<section>Some <strong>text</strong></section>returns the HTML of the given element
replaces the HTML in the given element
returns the text of the given element; if there are other HTML tags inside the element, you'll get a mixed bag of text from all elements
replaces the text inside the selected elements; if you try to insert HTML this way, you'll still get text
Last updated