forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetach.xml
37 lines (37 loc) · 1.32 KB
/
detach.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?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>