.html() | jquery out html
Description:SettheHTMLcontentsofeachelementinthesetofmatchedelements.The.html()methodisnotavailableinXMLdocuments.When.html()isusedtosetanelementscontent,anycontentthatwasinthatelementiscompletelyreplacedbythenewcontent.Additionally,jQueryremovesotherconstructssuchasdataandeventhandlersfromchildelementsbeforereplacingthoseelementswiththenewcontent.ConsiderthefollowingHTML:123
Description: Set the HTML contents of each element in the set of matched elements.
The .html() method is not available in XML documents.
When .html() is used to set an elements content, any content that was in that element is completely replaced by the new content. Additionally, jQuery removes other constructs such as data and event handlers from child elements before replacing those elements with the new content.
Consider the following HTML:
1
2
3
<div class="demo-container">
<div class="demo-box">Demonstration Box</div>
The content of <div class="demo-container"> can be set like this:
1
2
$( "div.demo-container" )
.html( "<p>All new content. <em>You bet!</em></p>...