-
Notifications
You must be signed in to change notification settings - Fork 265
/
Copy pathreplaceAll.xml
61 lines (61 loc) · 2.23 KB
/
replaceAll.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
<?xml version="1.0"?>
<entry type="method" name="replaceAll" return="jQuery">
<title>.replaceAll()</title>
<signature>
<added>1.2</added>
<argument name="target">
<desc>A selector string, jQuery object, DOM element, or array of elements indicating which element(s) to replace.</desc>
<type name="Selector"/>
<type name="jQuery"/>
<type name="Array"/>
<type name="Element"/>
</argument>
</signature>
<desc>Replace each target element with the set of matched elements.</desc>
<longdesc>
<p>The <code>.replaceAll()</code> method is similar to <code><a href="/replaceWith/">.replaceWith()</a></code>, but with the source and target reversed. Consider this DOM structure:</p>
<pre><code>
<div class="container">
<div class="inner first">Hello</div>
<div class="inner second">And</div>
<div class="inner third">Goodbye</div>
</div>
</code></pre>
<p>We can create an element, then replace other elements with it:</p>
<pre><code>$( "<h2>New heading</h2>" ).replaceAll( ".inner" );</code></pre>
<p>This causes all of them to be replaced:</p>
<pre><code>
<div class="container">
<h2>New heading</h2>
<h2>New heading</h2>
<h2>New heading</h2>
</div>
</code></pre>
<p>Or, we could select an element to use as the replacement:</p>
<pre><code>
$( ".first" ).replaceAll( ".third" );
</code></pre>
<p>This results in the DOM structure:</p>
<pre><code>
<div class="container">
<div class="inner second">And</div>
<div class="inner first">Hello</div>
</div>
</code></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>
</longdesc>
<note id="removes-data" type="additional" data-title=".replaceAll()"/>
<example>
<desc>Replace all the paragraphs with bold words.</desc>
<code><![CDATA[
$( "<b>Paragraph. </b>" ).replaceAll( "p" );
]]></code>
<html><![CDATA[
<p>Hello</p>
<p>cruel</p>
<p>World</p>
]]></html>
</example>
<category slug="manipulation/dom-replacement"/>
<category slug="version/1.2"/>
</entry>