Skip to content

Commit 148020b

Browse files
pobockskswedberg
authored andcommitted
Provisionally fixes jquery#173 - fixes desc and typo, but andSelf/addBack issue needs addressing
1 parent 08f32cf commit 148020b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

entries/andSelf.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</signature>
77
<desc>Add the previous set of elements on the stack to the current set.</desc>
88
<longdesc>
9-
<p>As described in the discussion for <code><a href="http://api.jquery.com/end/">.end()</a></code>, jQuery objects maintain aninternal stack that keeps track of changes to the matched set of elements. When one of the DOM traversal methods is called, the new set of elements is pushed onto the stack. If the previous set of elements is desired as well, <code>.andSelf()</code> can help.</p>
9+
<p>As described in the discussion for <code><a href="http://api.jquery.com/end/">.end()</a></code>, jQuery objects maintain an internal stack that keeps track of changes to the matched set of elements. When one of the DOM traversal methods is called, the new set of elements is pushed onto the stack. If the previous set of elements is desired as well, <code>.andSelf()</code> can help.</p>
1010
<p>Consider a page with a simple list on it:</p>
1111
<pre><code>
1212
&lt;ul&gt;
@@ -24,10 +24,14 @@
2424
<p>First, the initial selector locates item 3, initializing the stack with the set containing just this item. The call to <code>.nextAll()</code> then pushes the set of items 4 and 5 onto the stack. Finally, the <code>.andSelf()</code> invocation merges these two sets together, creating a jQuery object that points to all three items in document order: <code>{[&lt;li.third-item&gt;,&lt;li&gt;,&lt;li&gt; ]}</code>.</p>
2525
</longdesc>
2626
<example>
27-
<desc>Find all <code>div</code>s, and all the paragraphs inside of them, and give them both class names. Notice the <code>div</code> doesn't have the yellow background color since it didn't use <code>.andSelf()</code>.</desc>
27+
<desc>The <code>.andSelf()</code> method causes the previous set of DOM elements in the traversal stack to be added to the current set. In the first example, the top stack contains the set resulting from <code>.find("p")</code>. In the second example, <code>.andSelf()</code> adds the previous set of elements on the stack — in this case <code>$("div.after-andself")</code> — to the current set, selecting both the div and its enclosed paragraphs.</desc>
2828
<code><![CDATA[
2929
$("div.left, div.right").find("div, div > p").addClass("border");
30+
31+
// First Example
3032
$("div.before-andself").find("p").addClass("background");
33+
34+
// Second Example
3135
$("div.after-andself").find("p").andSelf().addClass("background");
3236
]]></code>
3337
<css><![CDATA[
@@ -56,4 +60,4 @@ p, div { margin:5px; padding:5px; }
5660
</example>
5761
<category slug="traversing/miscellaneous-traversal"/>
5862
<category slug="version/1.2"/>
59-
</entry>
63+
</entry>

0 commit comments

Comments
 (0)