forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappend.xml
140 lines (139 loc) · 6.19 KB
/
append.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
<?xml version="1.0"?>
<entry type="method" name="append" return="jQuery">
<title>.append()</title>
<signature>
<added>1.0</added>
<argument name="content">
<desc>DOM element, text node, array of elements and text nodes, HTML string, or jQuery object to insert at the end of 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 at the end of 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 at the end of 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, to the end of each element in the set of matched elements.</desc>
<longdesc>
<p>The <code>.append()</code> method inserts the specified content as the last child of each element in the jQuery collection (To insert it as the <em>first</em> child, use <a href="/prepend/"><code>.prepend()</code></a>).</p>
<p>The <code>.append()</code> and <code><a href="/appendTo/">.appendTo()</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>.append()</code>, the selector expression preceding the method is the container into which the content is inserted. With <code>.appendTo()</code>, on the other hand, the content precedes the method, either as a selector expression or as markup created on the fly, and it is inserted into the target container.</p>
<p>Consider the following HTML:</p>
<pre><code>
<h2>Greetings</h2>
<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
</div>
</code></pre>
<p>You can create content and insert it into several elements at once:</p>
<pre><code>
$( ".inner" ).append( "<p>Test</p>" );
</code></pre>
<p>Each inner <code><div></code> element gets this new content:</p>
<pre><code>
<h2>Greetings</h2>
<div class="container">
<div class="inner">
Hello
<p>Test</p>
</div>
<div class="inner">
Goodbye
<p>Test</p>
</div>
</div>
</code></pre>
<p>You can also select an element on the page and insert it into another:</p>
<pre><code>
$( ".container" ).append( $( "h2" ) );
</code></pre>
<p>If an element selected this way is inserted into a single location elsewhere in the DOM, it will be moved into the target (not cloned):</p>
<pre><code>
<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
<h2>Greetings</h2>
</div>
</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="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>.append()</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> as the last three child nodes of the body:</p>
<pre><code>
var $newdiv1 = $( "<div id='object1'></div>" ),
newdiv2 = document.createElement( "div" ),
existingdiv1 = document.getElementById( "foo" );
$( "body" ).append( $newdiv1, [ newdiv2, existingdiv1 ] );
</code></pre>
<p>Since <code>.append()</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>$('body').append( $newdiv1, newdiv2, existingdiv1 )</code>. The type and number of arguments will largely depend on how you collect the elements in your code.</p>
</longdesc>
<note id="html-code-execution" type="additional"/>
<note id="svg-support" type="additional"/>
<example>
<desc>Appends some HTML to all paragraphs.</desc>
<code><![CDATA[
$( "p" ).append( "<strong>Hello</strong>" );
]]></code>
<css><![CDATA[
p {
background: yellow;
}
]]></css>
<html><![CDATA[
<p>I would like to say: </p>
]]></html>
</example>
<example>
<desc>Appends an Element to all paragraphs.</desc>
<code><![CDATA[
$( "p" ).append( document.createTextNode( "Hello" ) );
]]></code>
<css><![CDATA[
p {
background: yellow;
}
]]></css>
<html><![CDATA[
<p>I would like to say: </p>
]]></html>
</example>
<example>
<desc>Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.</desc>
<code><![CDATA[
$( "p" ).append( $( "strong" ) );
]]></code>
<css><![CDATA[
p {
background: yellow;
}
]]></css>
<html><![CDATA[
<strong>Hello world!!!</strong>
<p>I would like to say: </p>
]]></html>
</example>
<category slug="manipulation/dom-insertion-inside"/>
<category slug="version/1.0"/>
<category slug="version/1.4"/>
</entry>