-
Notifications
You must be signed in to change notification settings - Fork 265
/
remove.xml
84 lines (84 loc) · 2.92 KB
/
remove.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?xml version="1.0"?>
<entry type="method" name="remove" return="jQuery">
<title>.remove()</title>
<signature>
<added>1.0</added>
<argument name="selector" optional="true" type="String">
<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>Similar to <code><a href="/empty/">.empty()</a></code>, the <code>.remove()</code> method takes elements out of the DOM. Use <code>.remove()</code> when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed. To remove the elements without removing data and events, use <code><a href="/detach/">.detach()</a></code> instead.</p>
<p>Consider the following HTML:</p>
<pre><code>
<div class="container">
<div class="hello">Hello</div>
<div class="goodbye">Goodbye</div>
</div>
</code></pre>
<p>We can target any element for removal:</p>
<pre><code>
$( ".hello" ).remove();
</code></pre>
<p>This will result in a DOM structure with the <code><div></code> element deleted:</p>
<pre><code>
<div class="container">
<div class="goodbye">Goodbye</div>
</div>
</code></pre>
<p>If we had any number of nested elements inside <code><div class="hello"></code>, they would be removed, too. Other jQuery constructs such as data or event handlers are erased as well.</p>
<p>We can also include a selector as an optional parameter. For example, we could rewrite the previous DOM removal code as follows:</p>
<pre><code>
$( "div" ).remove( ".hello" );
</code></pre>
<p>This would result in the same DOM structure:</p>
<pre><code>
<div class="container">
<div class="goodbye">Goodbye</div>
</div>
</code></pre>
</longdesc>
<example>
<desc>Removes all paragraphs from the DOM</desc>
<code><![CDATA[
$( "button" ).on( "click", function() {
$( "p" ).remove();
} );
]]></code>
<css><![CDATA[
p {
background: yellow;
margin: 6px 0;
}
]]></css>
<html><![CDATA[
<p>Hello</p>
how are
<p>you?</p>
<button>Call remove() on paragraphs</button>
]]></html>
</example>
<example>
<desc>Removes all paragraphs that contain "Hello" from the DOM. Analogous to doing <code>$("p").filter(":contains('Hello')").remove()</code>.</desc>
<code><![CDATA[
$( "button" ).on( "click", function() {
$( "p" ).remove( ":contains('Hello')" );
});
]]></code>
<css><![CDATA[
p {
background: yellow;
margin: 6px 0;
}
]]></css>
<html><![CDATA[
<p class="hello">Hello</p>
how are
<p>you?</p>
<button>Call remove( ":contains('Hello')" ) on paragraphs</button>
]]></html>
</example>
<category slug="manipulation/dom-removal"/>
<category slug="version/1.0"/>
</entry>