You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<desc>Add elements to the set of matched elements.</desc>
37
-
<longdesc><p>Given a jQuery object that represents a set of DOM elements, the <code>.add()</code> method constructs a new jQuery object from the union of those elements and the ones passed into the method. The argument to <code>.add()</code> can be pretty much anything that <code>$()</code> accepts, including a jQuery selector expression, references to DOM elements, or an HTML snippet.</p>
38
-
<p>The updated set of elements can be used in a following (chained) method, or assigned to a variable for later use. For example:</p>
39
-
<pre><code>
38
+
<longdesc>
39
+
<p>Given a jQuery object that represents a set of DOM elements, the <code>.add()</code> method constructs a new jQuery object from the union of those elements and the ones passed into the method. The argument to <code>.add()</code> can be pretty much anything that <code>$()</code> accepts, including a jQuery selector expression, references to DOM elements, or an HTML snippet.</p>
40
+
<p>The updated set of elements can be used in a following (chained) method, or assigned to a variable for later use. For example:</p>
41
+
<pre>
42
+
<code>
40
43
$("p").add("div").addClass("widget");
41
44
var pdiv = $("p").add("div");
42
-
</code></pre
108D7
span>>
43
-
<p>The following will <em>not</em> save the added elements, because the <code>.add()</code> method creates a new set and leaves the original set in pdiv unchanged:</p>
44
-
<pre><code>
45
+
</code>
46
+
</pre>
47
+
<p>The following will <em>not</em> save the added elements, because the <code>.add()</code> method creates a new set and leaves the original set in pdiv unchanged:</p>
48
+
<pre>
49
+
<code>
45
50
var pdiv = $("p");
46
51
pdiv.add("div"); // WRONG, pdiv will not change
47
-
</code></pre>
48
-
<p>Consider a page with a simple list and a paragraph following it:</p>
49
-
<pre><code><ul>
52
+
</code>
53
+
</pre>
54
+
<p>Consider a page with a simple list and a paragraph following it:</p>
55
+
<pre>
56
+
<code><ul>
50
57
<li>list item 1</li>
51
58
<li>list item 2</li>
52
59
<li>list item 3</li>
53
60
</ul>
54
-
<p>a paragraph</p></code></pre>
55
-
<p>We can select the list items and then the paragraph by using either a selector or a reference to the DOM element itself as the <code>.add()</code> method's argument:</p>
<p>The result of this call is a red background behind all four elements.
61
+
<p>a paragraph</p></code>
62
+
</pre>
63
+
<p>We can select the list items and then the paragraph by using either a selector or a reference to the DOM element itself as the <code>.add()</code> method's argument:</p>
<p>The result of this call is a red background behind all four elements.
61
73
Using an HTML snippet as the <code>.add()</code> method's argument (as in the third version), we can create additional elements on the fly and add those elements to the matched set of elements. Let's say, for example, that we want to alter the background of the list items along with a newly created paragraph:</p>
<p>Although the new paragraph has been created and its background color changed, it still does not appear on the page. To place it on the page, we could add one of the insertion methods to the chain.</p>
65
-
<p>As of jQuery 1.4 the results from .add() will always be returned in document order (rather than a simple concatenation).</p>
66
-
<p><strong>Note:</strong> To reverse the <code>.add()</code> you can use <ahref="http://api.jquery.com/not"><code>.not( elements | selector )</code></a> to remove elements from the jQuery results, or <ahref="http://api.jquery.com/end"><code>.end()</code></a> to return to the selection before you added.</p>
67
-
</longdesc>
68
-
<example>
69
-
<desc>Finds all divs and makes a border. Then adds all paragraphs to the jQuery object to set their backgrounds yellow.</desc>
<p>Although the new paragraph has been created and its background color changed, it still does not appear on the page. To place it on the page, we could add one of the insertion methods to the chain.</p>
79
+
<p>As of jQuery 1.4 the results from .add() will always be returned in document order (rather than a simple concatenation).</p>
80
+
<p><strong>Note:</strong> To reverse the <code>.add()</code> you can use <ahref="http://api.jquery.com/not"><code>.not( elements | selector )</code></a> to remove elements from the jQuery results, or <ahref="http://api.jquery.com/end"><code>.end()</code></a> to return to the selection before you added.</p>
81
+
</longdesc>
82
+
<example>
83
+
<desc>Finds all divs and makes a border. Then adds all paragraphs to the jQuery object to set their backgrounds yellow.</desc>
84
+
<code><![CDATA[
71
85
72
86
$("div").css("border", "2px solid red")
73
87
.add("p")
74
88
.css("background", "yellow");
75
89
]]></code>
76
-
<css><![CDATA[
90
+
<css><![CDATA[
77
91
div { width:60px; height:60px; margin:10px; float:left; }
<desc>Adds the specified class(es) to each of the set of matched elements.</desc>
16
-
<longdesc><p>It's important to note that this method does not replace a class. It simply adds the class, appending it to any which may already be assigned to the elements.</p>
17
-
<p>More than one class may be added at a time, separated by a space, to the set of matched elements, like so:</p>
18
-
<pre>$("p").addClass("myClass yourClass");</pre>
19
-
<p>This method is often used with <code>.removeClass()</code> to switch elements' classes from one to another, like so:</p>
<p>Here, the <code>myClass</code> and <code>noClass</code> classes are removed from all paragraphs, while <code>yourClass</code> is added.</p>
22
-
<p>As of jQuery 1.4, the <code>.addClass()</code> method's argument can receive a function.</p>
23
-
<pre>$("ul li:last").addClass(function(index) {
17
+
<longdesc>
18
+
<p>It's important to note that this method does not replace a class. It simply adds the class, appending it to any which may already be assigned to the elements.</p>
19
+
<p>More than one class may be added at a time, separated by a space, to the set of matched elements, like so:</p>
20
+
<pre>$("p").addClass("myClass yourClass");</pre>
21
+
<p>This method is often used with <code>.removeClass()</code> to switch elements' classes from one to another, like so:</p>
Copy file name to clipboardExpand all lines: entries/after.xml
+20-24Lines changed: 20 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
-
<entrytype='method'name="after"return="jQuery">
1
+
<?xml version="1.0"?>
2
+
<entrytype="method"name="after"return="jQuery">
2
3
<title>.after()</title>
3
4
<signature>
4
5
<added>1.0</added>
@@ -16,29 +17,24 @@
16
17
</argument>
17
18
</signature>
18
19
<desc>Insert content, specified by the parameter, after each element in the set of matched elements.</desc>
19
-
<longdesc><p>The <code>.after()</code> and <code><ahref='/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 selector expression preceding the method is the container after which the content is inserted. With <code>.insertAfter()</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 after the target container.</p>
20
-
20
+
<longdesc>
21
+
<p>The <code>.after()</code> and <code><ahref="/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 selector expression preceding the method is the container after which the content is inserted. With <code>.insertAfter()</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 after the target container.</p>
21
22
<p>Using the following HTML:</p>
22
23
<pre><div class="container">
23
24
<h2>Greetings</h2>
24
25
<div class="inner">Hello</div>
25
26
<div class="inner">Goodbye</div>
26
27
</div></pre>
27
-
28
28
<p>Content can be created and then inserted after several elements at once:</p>
<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>
80
-
</longdesc>
76
+
</longdesc>
81
77
<example>
82
-
<desc>Inserts some HTML after all paragraphs.</desc>
0 commit comments