Skip to content

Commit 701567c

Browse files
agcolomscottgonzalez
authored andcommitted
Code indentation and formatting (a entries).
1 parent 0cb661e commit 701567c

22 files changed

+608
-381
lines changed

entries/add.xml

+79-54
Original file line numberDiff line numberDiff line change
@@ -36,97 +36,122 @@
3636
</signature>
3737
<desc>Add elements to the set of matched elements.</desc>
3838
<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>
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>
4040
<p>Do not assume that this method appends the elements to the existing collection in the order they are passed to the <code>.add()</code> method. When all elements are members of the same document, the resulting collection from <code>.add()</code> will be sorted in document order; that is, in order of each element's appearance in the document. If the collection consists of elements from different documents or ones not in any document, the sort order is undefined. To create a jQuery object with elements in a well-defined order, use the <code>$(array_of_DOM_elements)</code> signature.</p>
4141
<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>
42-
<pre>
43-
<code>
44-
$("p").add("div").addClass("widget");
45-
var pdiv = $("p").add("div");
46-
</code>
47-
</pre>
42+
<pre><code>
43+
$( "p" ).add( "div" ).addClass( "widget" );
44+
var pdiv = $( "p" ).add( "div" );
45+
</code></pre>
4846
<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>
49-
<pre>
50-
<code>
51-
var pdiv = $("p");
52-
pdiv.add("div"); // WRONG, pdiv will not change
53-
</code>
54-
</pre>
47+
<pre><code>
48+
var pdiv = $( "p" );
49+
pdiv.add( "div" ); // WRONG, pdiv will not change
50+
</code></pre>
5551
<p>Consider a page with a simple list and a paragraph following it:</p>
56-
<pre>
57-
<code>&lt;ul&gt;
52+
<pre><code>
53+
&lt;ul&gt;
5854
&lt;li&gt;list item 1&lt;/li&gt;
5955
&lt;li&gt;list item 2&lt;/li&gt;
6056
&lt;li&gt;list item 3&lt;/li&gt;
6157
&lt;/ul&gt;
62-
&lt;p&gt;a paragraph&lt;/p&gt;</code>
63-
</pre>
58+
&lt;p&gt;a paragraph&lt;/p&gt;
59+
</code></pre>
6460
<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>
65-
<pre>
66-
<code>$('li').add('p').css('background-color', 'red');</code>
67-
</pre>
61+
<pre><code>$( "li" ).add( "p" ).css( "background-color", "red" );</code></pre>
6862
<p>Or:</p>
69-
<pre>
70-
<code>$('li').add(document.getElementsByTagName('p')[0])
71-
.css('background-color', 'red');</code>
72-
</pre>
63+
<pre><code>
64+
$( "li" ).add( document.getElementsByTagName( "p" )[ 0 ] )
65+
.css( "background-color", "red" );
66+
</code></pre>
7367
<p>The result of this call is a red background behind all four elements.
7468
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>
75-
<pre>
76-
<code>$('li').add('&lt;p id="new"&gt;new paragraph&lt;/p&gt;')
77-
.css('background-color', 'red');</code>
78-
</pre>
69+
<pre><code>
70+
$( "li" ).add( "&lt;p id='new'&gt;new paragraph&lt;/p&gt;" )
71+
.css( "background-color", "red" );
72+
</code></pre>
7973
<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>
8074
<p>As of jQuery 1.4 the results from .add() will always be returned in document order (rather than a simple concatenation).</p>
8175
<p><strong>Note:</strong> To reverse the <code>.add()</code> you can use <a href="http://api.jquery.com/not"><code>.not( elements | selector )</code></a> to remove elements from the jQuery results, or <a href="http://api.jquery.com/end"><code>.end()</code></a> to return to the selection before you added.</p>
8276
</longdesc>
8377
<example>
8478
<desc>Finds all divs and makes a border. Then adds all paragraphs to the jQuery object to set their backgrounds yellow.</desc>
8579
<code><![CDATA[
86-
87-
$("div").css("border", "2px solid red")
88-
.add("p")
89-
.css("background", "yellow");
80+
$( "div" ).css( "border", "2px solid red" )
81+
.add( "p" )
82+
.css( "background", "yellow" );
9083
]]></code>
9184
<css><![CDATA[
92-
div { width:60px; height:60px; margin:10px; float:left; }
93-
p { clear:left; font-weight:bold; font-size:16px;
94-
color:blue; margin:0 10px; padding:2px; }
95-
]]></css>
96-
<html><![CDATA[<div></div>
85+
div {
86+
width: 60px;
87+
height: 60px;
88+
margin: 10px;
89+
float: left;
90+
}
91+
p {
92+
clear: left;
93+
font-weight: bold;
94+
font-size: 16px;
95+
color: blue;
96+
margin: 0 10px;
97+
padding: 2px;
98+
}
99+
]]></css>
100+
<html><![CDATA[
101+
<div></div>
97102
98-
<div></div>
99-
<div></div>
100-
<div></div>
101-
<div></div>
102-
<div></div>
103+
<div></div>
104+
<div></div>
105+
<div></div>
106+
<div></div>
107+
<div></div>
103108
104-
<p>Added this... (notice no border)</p>]]></html>
109+
<p>Added this... (notice no border)</p>
110+
]]></html>
105111
</example>
106112
<example>
107113
<desc>Adds more elements, matched by the given expression, to the set of matched elements.</desc>
108-
<code><![CDATA[$("p").add("span").css("background", "yellow");]]></code>
109-
<html><![CDATA[<p>Hello</p><span>Hello Again</span>]]></html>
114+
<code><![CDATA[
115+
$( "p" ).add( "span" ).css( "background", "yellow" );
116+
]]></code>
117+
<html><![CDATA[
118+
<p>Hello</p>
119+
<span>Hello Again</span>
120+
]]></html>
110121
</example>
111122
<example>
112123
<desc>Adds more elements, created on the fly, to the set of matched elements.</desc>
113-
<code><![CDATA[$("p").clone().add("<span>Again</span>").appendTo(document.body);]]></code>
114-
<html><![CDATA[<p>Hello</p>]]></html>
124+
<code><![CDATA[
125+
$( "p" ).clone().add( "<span>Again</span>" ).appendTo( document.body );
126+
]]></code>
127+
<html><![CDATA[
128+
<p>Hello</p>
129+
]]></html>
115130
</example>
116131
<example>
117132
<desc>Adds one or more Elements to the set of matched elements.</desc>
118-
<code><![CDATA[$("p").add(document.getElementById("a")).css("background", "yellow");]]></code>
119-
<html><![CDATA[<p>Hello</p><span id="a">Hello Again</span>]]></html>
133+
<code><![CDATA[
134+
$( "p" ).add( document.getElementById( "a" ) ).css( "background", "yellow" );
135+
]]></code>
136+
<html><![CDATA[
137+
<p>Hello</p>
138+
<span id="a">Hello Again</span>
139+
]]></html>
120140
</example>
121141
<example>
122142
<desc>Demonstrates how to add (or push) elements to an existing collection</desc>
123-
<code><![CDATA[var collection = $("p");
143+
<code><![CDATA[
144+
var collection = $( "p" );
124145
// capture the new collection
125-
collection = collection.add(document.getElementById("a"));
126-
collection.css("background", "yellow");]]></code>
127-
<html><![CDATA[<p>Hello</p><span id="a">Hello Again</span>]]></html>
146+
collection = collection.add( document.getElementById( "a" ) );
147+
collection.css( "background", "yellow" );
148+
]]></code>
149+
<html><![CDATA[
150+
<p>Hello</p>
151+
<span id="a">Hello Again</span>
152+
]]></html>
128153
</example>
129154
<category slug="traversing/miscellaneous-traversal"/>
130155
<category slug="version/1.0"/>
131156
<category slug="version/1.4"/>
132-
</entry>
157+
</entry>

entries/addBack.xml

+29-17
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,49 @@
1313
<p>Consider a page with a simple list on it:</p>
1414
<pre><code>
1515
&lt;ul&gt;
16-
&lt;li&gt;list item 1&lt;/li&gt;
17-
&lt;li&gt;list item 2&lt;/li&gt;
18-
&lt;li class="third-item"&gt;list item 3&lt;/li&gt;
19-
&lt;li&gt;list item 4&lt;/li&gt;
20-
&lt;li&gt;list item 5&lt;/li&gt;
16+
&lt;li&gt;list item 1&lt;/li&gt;
17+
&lt;li&gt;list item 2&lt;/li&gt;
18+
&lt;li class="third-item"&gt;list item 3&lt;/li&gt;
19+
&lt;li&gt;list item 4&lt;/li&gt;
20+
&lt;li&gt;list item 5&lt;/li&gt;
2121
&lt;/ul&gt;
22-
</code></pre>
22+
</code></pre>
2323
<p>The result of the following code is a red background behind items 3, 4 and 5:</p>
24-
<pre><code>$('li.third-item').nextAll().addBack()
25-
.css('background-color', 'red');
24+
<pre><code>$( "li.third-item" ).nextAll().addBack()
25+
.css( "background-color", "red" );
2626
</code></pre>
2727
<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>.addBack()</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>
2828
</longdesc>
2929
<example>
3030
<desc>The <code>.addBack()</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>.addBack()</code> adds the previous set of elements on the stack — in this case <code>$("div.after-addback")</code> — to the current set, selecting both the div and its enclosed paragraphs.</desc>
3131
<code><![CDATA[
32-
$("div.left, div.right").find("div, div > p").addClass("border");
32+
$( "div.left, div.right" ).find( "div, div > p" ).addClass( "border" );
3333
3434
// First Example
35-
$("div.before-addback").find("p").addClass("background");
35+
$( "div.before-addback" ).find( "p" ).addClass( "background" );
3636
3737
// Second Example
38-
$("div.after-addback").find("p").addBack().addClass("background");
38+
$( "div.after-addback" ).find( "p" ).addBack().addClass( "background" );
3939
]]></code>
4040
<css><![CDATA[
41-
p, div { margin:5px; padding:5px; }
42-
.border { border: 2px solid red; }
43-
.background { background:yellow; }
44-
.left, .right { width: 45%; float: left;}
45-
.right { margin-left:3%; }
46-
]]></css>
41+
p, div {
42+
margin: 5px;
43+
padding: 5px;
44+
}
45+
.border {
46+
border: 2px solid red;
47+
}
48+
.background {
49+
background: yellow;
50+
}
51+
.left, .right {
52+
width: 45%;
53+
float: left;
54+
}
55+
.right {
56+
margin-left: 3%;
57+
}
58+
]]></css>
4759
<html><![CDATA[
4860
<div class="left">
4961
<p><strong>Before <code>addBack()</code></strong></p>

entries/addClass.xml

+60-32
Original file line numberDiff line numberDiff line change
@@ -17,64 +17,92 @@
1717
<longdesc>
1818
<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>
1919
<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><code>$("p").addClass("myClass yourClass");</code></pre>
20+
<pre><code>
21+
$( "p" ).addClass( "myClass yourClass" );
22+
</code></pre>
2123
<p>This method is often used with <code>.removeClass()</code> to switch elements' classes from one to another, like so:</p>
22-
<pre><code>$("p").removeClass("myClass noClass").addClass("yourClass");</code></pre>
24+
<pre><code>
25+
$( "p" ).removeClass( "myClass noClass" ).addClass( "yourClass" );
26+
</code></pre>
2327
<p>Here, the <code>myClass</code> and <code>noClass</code> classes are removed from all paragraphs, while <code>yourClass</code> is added.</p>
2428
<p>As of jQuery 1.4, the <code>.addClass()</code> method's argument can receive a function.</p>
25-
<pre><code>$("ul li").addClass(function(index) {
29+
<pre><code>
30+
$( "ul li" ).addClass(function( index ) {
2631
return "item-" + index;
27-
});</code></pre>
32+
});
33+
</code></pre>
2834
<p>Given an unordered list with two <code>&lt;li&gt;</code> elements, this example adds the class "item-0" to the first <code>&lt;li&gt;</code> and "item-1" to the second.</p>
2935
</longdesc>
3036
<example>
3137
<desc>Add the class "selected" to the matched elements.</desc>
3238
<code><![CDATA[
33-
$("p").last().addClass("selected");
34-
]]></code>
39+
$( "p" ).last().addClass( "selected" );
40+
]]></code>
3541
<css><![CDATA[
36-
p { margin: 8px; font-size:16px; }
37-
.selected { color:blue; }
38-
.highlight { background:yellow; }
42+
p {
43+
margin: 8px;
44+
font-size:16px;
45+
}
46+
.selected {
47+
color:blue;
48+
}
49+
.highlight {
50+
background:yellow;
51+
}
3952
]]></css>
4053
<html><![CDATA[
41-
<p>Hello</p>
42-
<p>and</p>
43-
<p>Goodbye</p>
44-
]]></html>
54+
<p>Hello</p>
55+
<p>and</p>
56+
<p>Goodbye</p>
57+
]]></html>
4558
</example>
4659
<example>
4760
<desc>Add the classes "selected" and "highlight" to the matched elements.</desc>
4861
<code><![CDATA[
49-
$("p:last").addClass("selected highlight");
50-
]]></code>
62+
$( "p:last" ).addClass( "selected highlight" );
63+
]]></code>
5164
<css><![CDATA[
52-
p { margin: 8px; font-size:16px; }
53-
.selected { color:red; }
54-
.highlight { background:yellow; }
65+
p {
66+
margin: 8px;
67+
font-size: 16px;
68+
}
69+
.selected {
70+
color: red;
71+
}
72+
.highlight {
73+
background: yellow;
74+
}
5575
]]></css>
56-
<html><![CDATA[<p>Hello</p>
57-
<p>and</p>
58-
<p>Goodbye</p>]]></html>
76+
<html><![CDATA[
77+
<p>Hello</p>
78+
<p>and</p>
79+
<p>Goodbye</p>
80+
]]></html>
5981
</example>
6082
<example>
6183
<desc>Pass in a function to <code>.addClass()</code> to add the "green" class to a div that already has a "red" class.</desc>
6284
<code><![CDATA[
63-
$("div").addClass(function(index, currentClass) {
64-
var addedClass;
85+
$( "div" ).addClass(function( index, currentClass ) {
86+
var addedClass;
6587
66-
if ( currentClass === "red" ) {
67-
addedClass = "green";
68-
$("p").text("There is one green div");
69-
}
88+
if ( currentClass === "red" ) {
89+
addedClass = "green";
90+
$( "p" ).text( "There is one green div" );
91+
}
7092
71-
return addedClass;
72-
});
93+
return addedClass;
94+
});
7395
]]></code>
7496
<css><![CDATA[
75-
div { background: white; }
76-
.red { background: red; }
77-
.red.green { background: green; }
97+
div {
98+
background: white;
99+
}
100+
.red {
101+
background: red;
102+
}
103+
.red.green {
104+
background: green;
105+
}
78106
]]></css>
79107
<html><![CDATA[
80108
<div>This div should be white</div>

0 commit comments

Comments
 (0)