<pclass="arguement"><strong>newContent</strong>The content to insert. May be an HTML string, DOM element, or jQuery object.</p>
</li>
<liclass="signature"id="replaceWith-function">
<h4class="name">
<spanclass="versionAdded">version added: <ahref="/category/version/1.4/">1.4</a></span>.replaceWith( function )</h4>
<pclass="arguement"><strong>function</strong>A function that returns an HTML string to replace the set of matched elements with.</p>
</li>
</ul>
<divclass="longdesc">
<p>The <code>.replaceWith()</code> method allows us to remove content from the DOM and insert new content in its place with a single call. Consider this DOM structure:</p>
<p>Or, we could select an element to use as the replacement:</p>
<pre>$('.third').replaceWith($('.first'));</pre>
<p>This results in the DOM structure:</p>
<pre><div class="container">
<div class="inner second">And</div>
<div class="inner first">Hello</div>
</div></pre>
<p>From this example, we can see that the selected element replaces the target by being moved from its old location, not by being cloned.</p>
<p>The <code>.replaceWith()</code> method, like most jQuery methods, returns the jQuery object so that other methods can be chained onto it. However, it must be noted that the <emphasisrole="italics">original</emphasis> jQuery object is returned. This object refers to the element that has been removed from the DOM, not the new element that has replaced it.</p>
<p>In jQuery 1.4 replaceWith, before, and after will also work on disconnected DOM nodes. For example if you were to do:</p>
<h4>Example: <spanclass="desc">On click, replace each paragraph with a jQuery div object that is already in the DOM. Notice it doesn't clone the object but rather moves it to replace the paragraph.</span>