<p>This method is not available on XML documents.</p>
<p>In an HTML document, we can use <code>.html()</code> to get the contents of any element. If the selector expression matches more than one element, only the first one's HTML content is returned. Consider this code:</p>
<pre>$('div.demo-container').html();</pre>
<p>In order for the following <code><div></code>'s content to be retrieved, it would have to be the first one with <code>class="demo-container"</code> in the document:</p>
<pclass="arguement"><strong>function(index, html)</strong>A function returning the HTML content to set. Receives the index position of the element in the set and the old HTML value as arguments.</p>
</li>
</ul>
<divclass="longdesc">
<p>The <code>.html()</code> method is not available in XML documents. </p>
<p>When we use <code>.html()</code> to set elements' contents, any contents that were in those elements is completely replaced by the new contents. Consider the following HTML:</p>
<p>We can set the HTML contents of <code><div class="demo-container"></code> like so:</p>
<pre>$('div.demo-container')
.html('<p>All new content. <em>You bet!</em></p>');</pre>
<p>That line of code will replace everything inside <code><div class="demo-container"></code>:</p>
<pre><div class="demo-container">
<p>All new content. <em>You bet!</em></p>
</div></pre>
<p>As of jQuery 1.4, the <code>.html()</code> method allows us to set the HTML content by passing in a function.</p>
<pre>$('div.demo-container').html(function() {
var emph = '<em>' + $('p').length + ' paragraphs!</em>';
return '<p>All new content for ' + emph + '</p>';
});</pre>
<p>Given a document with six paragraphs, this example will set the HTML of <code><div class="demo-container"></code> to <code><p>All new content for <em>6 paragraphs!</em></p></code>.</p>
</div>
<h3>Examples:</h3>
<divid="entry-examples"class="entry-examples">
<divid="example-0">
<h4>Example: <spanclass="desc">Add some html to each div.</span>