Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

37 lines (37 sloc) 1.354 kB
<?xml version="1.0"?>
<entry type="method" name="detach" return="jQuery">
<title>.detach()</title>
<signature>
<added>1.4</added>
<argument name="selector" optional="true" type="Selector">
<desc>A selector expression that filters the set of matched elements to be removed.</desc>
</argument>
</signature>
<desc>Remove the set of matched elements from the DOM.</desc>
<longdesc>
<p>The <code>.detach()</code> method is the same as <code><a href="/remove">.remove()</a></code>, except that <code>.detach()</code> keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.</p>
</longdesc>
<example>
<desc>Detach all paragraphs from the DOM</desc>
<code><![CDATA[
$("p").click(function(){
$(this).toggleClass("off");
});
var p;
$("button").click(function(){
if ( p ) {
p.appendTo("body");
p = null;
} else {
p = $("p").detach();
}
});]]></code>
<css><![CDATA[p { background:yellow; margin:6px 0; } p.off { background: black; }]]></css>
<html><![CDATA[<p>Hello</p>
how are
<p>you?</p>
<button>Attach/detach paragraphs</button>]]></html>
</example>
<category slug="manipulation/dom-removal"/>
<category slug="version/1.4"/>
</entry>
Jump to Line
Something went wrong with that request. Please try again.