forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathafter.xml
155 lines (154 loc) · 7.07 KB
/
after.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?xml version="1.0"?>
<entry type="method" name="after" return="jQuery">
<title>.after()</title>
<signature>
<added>1.0</added>
<argument name="content">
<desc>HTML string, DOM element, text node, array of elements and text nodes, or jQuery object to insert after each element in the set of matched elements.</desc>
<type name="htmlString"/>
<type name="Element"/>
<type name="Text"/>
<type name="Array"/>
<type name="jQuery"/>
</argument>
<argument name="content" optional="true">
<desc>One or more additional DOM elements, text nodes, arrays of elements and text nodes, HTML strings, or jQuery objects to insert after each element in the set of matched elements.</desc>
<type name="htmlString"/>
<type name="Element"/>
<type name="Text"/>
<type name="Array"/>
<type name="jQuery"/>
</argument>
</signature>
<signature>
<added>1.4</added>
<argument name="function" type="Function">
<desc>A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert after each element in the set of matched elements. Receives the index position of the element in the set as an argument. Within the function, <code>this</code> refers to the current element in the set.</desc>
<argument name="index" type="Integer" />
<return>
<type name="htmlString"/>
<type name="Element"/>
<type name="Text"/>
<type name="jQuery"/>
</return>
</argument>
</signature>
<signature>
<added>1.10</added>
<argument name="function-html" type="Function">
<desc>A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert after each element in the set of matched elements. Receives the index position of the element in the set and the old HTML value of the element as arguments. Within the function, <code>this</code> refers to the current element in the set.</desc>
<argument name="index" type="Integer" />
<argument name="html" type="String" />
<return>
<type name="htmlString"/>
<type name="Element"/>
<type name="Text"/>
<type name="jQuery"/>
</return>
</argument>
</signature>
<desc>Insert content, specified by the parameter, after each element in the set of matched elements.</desc>
<longdesc>
<p>The <code>.after()</code> and <code><a href="/insertAfter/">.insertAfter()</a></code> methods perform the same task. The major difference is in the syntax—specifically, in the placement of the content and target. With <code>.after()</code>, the content to be inserted comes from the method's argument: <code>$(target).after(contentToBeInserted)</code>. With <code>.insertAfter()</code>, on the other hand, the content precedes the method and is inserted after the target, which in turn is passed as the <code>.insertAfter()</code> method's argument: <code>$(contentToBeInserted).insertAfter(target)</code>.</p>
<p>Using the following HTML:</p>
<pre><code>
<div class="container">
<h2>Greetings</h2>
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
</div>
</code></pre>
<p>Content can be created and then inserted after several elements at once:</p>
<pre><code>
$( ".inner" ).after( "<p>Test</p>" );
</code></pre>
<p>Each inner <code><div></code> element gets this new content:</p>
<pre><code>
<div class="container">
<h2>Greetings</h2>
<div class="inner">Hello</div>
<p>Test</p>
<div class="inner">Goodbye</div>
<p>Test</p>
</div></code></pre>
<p>An element in the DOM can also be selected and inserted after another element:</p>
<pre><code>
$( ".container" ).after( $( "h2" ) );
</code></pre>
<p>If an element selected this way is inserted into a single location elsewhere in the DOM, it will be moved rather than cloned:</p>
<pre><code>
<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
</div>
<h2>Greetings</h2>
</code></pre>
<p><strong>Important</strong>: If there is more than one target element, however, cloned copies of the inserted element will be created for each target except for the last one.</p>
<h4 id="passing-a-function">Passing a Function</h4>
<p>As of jQuery 1.4, <code>.after()</code> supports passing a function that returns the elements to insert.</p>
<pre><code>
$( "p" ).after(function() {
return "<div>" + this.className + "</div>";
});
</code></pre>
<p>This example inserts a <code><div></code> after each paragraph, with each new <code><div></code> containing the class name(s) of its preceding paragraph.</p>
<h4 id="additional-arguments">Additional Arguments</h4>
<p>Similar to other content-adding methods such as <code><a href="/prepend/">.prepend()</a></code> and <code><a href="/before/">.before()</a></code>, <code>.after()</code> also supports passing in multiple arguments as input. Supported input includes DOM elements, jQuery objects, HTML strings, and arrays of DOM elements.</p>
<p>For example, the following will insert two new <code><div></code>s and an existing <code><div></code> after the first paragraph:</p>
<pre><code>
var $newdiv1 = $( "<div id='object1'></div>" ),
newdiv2 = document.createElement( "div" ),
existingdiv1 = document.getElementById( "foo" );
$( "p" ).first().after( $newdiv1, [ newdiv2, existingdiv1 ] );
</code></pre>
<p>Since <code>.after()</code> can accept any number of additional arguments, the same result can be achieved by passing in the three <code><div></code>s as three separate arguments, like so: <code>$( "p" ).first().after( $newdiv1, newdiv2, existingdiv1 )</code>. The type and number of arguments will largely depend on the elements that are collected in the code.</p>
</longdesc>
<note id="disconnected-manipulation" type="additional" data-title=".after()"/>
<note id="html-code-execution" type="additional"/>
<example>
<desc>Inserts some HTML after all paragraphs.</desc>
<code><![CDATA[
$( "p" ).after( "<b>Hello</b>" );
]]></code>
<css><![CDATA[
p {
background: yellow;
}
]]></css>
<html><![CDATA[
<p>I would like to say: </p>
]]></html>
</example>
<example>
<desc>Inserts a DOM element after all paragraphs.</desc>
<code><![CDATA[
$( "p" ).after( document.createTextNode( "Hello" ) );
]]></code>
<css><![CDATA[
p {
background: yellow;
}
]]></css>
<html><![CDATA[
<p>I would like to say: </p>
]]></html>
</example>
<example>
<desc>Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.</desc>
<code><![CDATA[
$( "p" ).after( $( "b" ) );
]]></code>
<css><![CDATA[
p {
background: yellow;
}
]]></css>
<html><![CDATA[
<b>Hello</b>
<p>I would like to say: </p>
]]></html>
</example>
<category slug="manipulation/dom-insertion-outside"/>
<category slug="version/1.0"/>
<category slug="version/1.4"/>
</entry>