Skip to content

Commit da2612f

Browse files
committed
api docs: code indentation and formatting (remaining n entries)
1 parent b769765 commit da2612f

File tree

8 files changed

+269
-148
lines changed

8 files changed

+269
-148
lines changed

entries/next.xml

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,50 @@
1414
<p>Consider a page with a simple list on it:</p>
1515
<pre><code>
1616
&lt;ul&gt;
17-
&lt;li&gt;list item 1&lt;/li&gt;
18-
&lt;li&gt;list item 2&lt;/li&gt;
19-
&lt;li class="third-item"&gt;list item 3&lt;/li&gt;
20-
&lt;li&gt;list item 4&lt;/li&gt;
21-
&lt;li&gt;list item 5&lt;/li&gt;
17+
&lt;li&gt;list item 1&lt;/li&gt;
18+
&lt;li&gt;list item 2&lt;/li&gt;
19+
&lt;li class="third-item"&gt;list item 3&lt;/li&gt;
20+
&lt;li&gt;list item 4&lt;/li&gt;
21+
&lt;li&gt;list item 5&lt;/li&gt;
2222
&lt;/ul&gt;
2323
</code></pre>
2424
<p>If we begin at the third item, we can find the element which comes just after it:</p>
25-
<pre><code>$('li.third-item').next().css('background-color', 'red');</code></pre>
25+
<pre><code>
26+
$( "li.third-item" ).next().css( "background-color", "red" );
27+
</code></pre>
2628
<p>The result of this call is a red background behind item 4. Since we do not supply a selector expression, this following element is unequivocally included as part of the object. If we had supplied one, the element would be tested for a match before it was included.</p>
2729
</longdesc>
2830
<example>
2931
<desc>Find the very next sibling of each disabled button and change its text "this button is disabled".</desc>
30-
<code><![CDATA[$("button[disabled]").next().text("this button is disabled");]]></code>
32+
<code><![CDATA[
33+
$( "button[disabled]" ).next().text( "this button is disabled" );
34+
]]></code>
3135
<css><![CDATA[
32-
33-
span { color:blue; font-weight:bold; }
34-
button { width:100px; }
35-
]]></css>
36-
<html><![CDATA[<div><button disabled="disabled">First</button> - <span></span></div>
37-
<div><button>Second</button> - <span></span></div>
38-
39-
<div><button disabled="disabled">Third</button> - <span></span></div>]]></html>
36+
span {
37+
color: blue;
38+
font-weight: bold;
39+
}
40+
button {
41+
width: 100px;
42+
}
43+
]]></css>
44+
<html><![CDATA[
45+
<div><button disabled="disabled">First</button> - <span></span></div>
46+
<div><button>Second</button> - <span></span></div>
47+
<div><button disabled="disabled">Third</button> - <span></span></div>
48+
]]></html>
4049
</example>
4150
<example>
4251
<desc>Find the very next sibling of each paragraph. Keep only the ones with a class "selected".</desc>
43-
<code><![CDATA[$("p").next(".selected").css("background", "yellow");]]></code>
44-
<html><![CDATA[<p>Hello</p>
45-
46-
<p class="selected">Hello Again</p>
47-
<div><span>And Again</span></div>]]></html>
52+
<code><![CDATA[
53+
$( "p" ).next( ".selected" ).css( "background", "yellow" );
54+
]]></code>
55+
<html><![CDATA[
56+
<p>Hello</p>
57+
<p class="selected">Hello Again</p>
58+
<div><span>And Again</span></div>
59+
]]></html>
4860
</example>
4961
<category slug="traversing/tree-traversal"/>
5062
<category slug="version/1.0"/>
51-
</entry>
63+
</entry>

entries/nextAll.xml

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,73 @@
1414
<p>Consider a page with a simple list on it:</p>
1515
<pre><code>
1616
&lt;ul&gt;
17-
&lt;li&gt;list item 1&lt;/li&gt;
18-
&lt;li&gt;list item 2&lt;/li&gt;
19-
&lt;li class="third-item"&gt;list item 3&lt;/li&gt;
20-
&lt;li&gt;list item 4&lt;/li&gt;
21-
&lt;li&gt;list item 5&lt;/li&gt;
17+
&lt;li&gt;list item 1&lt;/li&gt;
18+
&lt;li&gt;list item 2&lt;/li&gt;
19+
&lt;li class="third-item"&gt;list item 3&lt;/li&gt;
20+
&lt;li&gt;list item 4&lt;/li&gt;
21+
&lt;li&gt;list item 5&lt;/li&gt;
2222
&lt;/ul&gt;
23-
</code></pre>
23+
</code></pre>
2424
<p>If we begin at the third item, we can find the elements which come after it:</p>
25-
<pre><code>$('li.third-item').nextAll().css('background-color', 'red');</code></pre>
25+
<pre><code>
26+
$( "li.third-item" ).nextAll().css( "background-color", "red" );
27+
</code></pre>
2628
<p>The result of this call is a red background behind items 4 and 5. Since we do not supply a selector expression, these following elements are unequivocally included as part of the object. If we had supplied one, the elements would be tested for a match before they were included.</p>
2729
</longdesc>
2830
<example>
2931
<desc>Locate all the divs after the first and give them a class.</desc>
30-
<code><![CDATA[$("div:first").nextAll().addClass("after");]]></code>
32+
<code><![CDATA[
33+
$( "div:first" ).nextAll().addClass( "after" );
34+
]]></code>
3135
<css><![CDATA[
32-
div { width: 80px; height: 80px; background: #abc;
33-
border: 2px solid black; margin: 10px; float: left; }
34-
div.after { border-color: red; }
35-
]]></css>
36+
div {
37+
width: 80px;
38+
height: 80px;
39+
background: #abc;
40+
border: 2px solid black;
41+
margin: 10px;
42+
float: left;
43+
}
44+
div.after {
45+
border-color: red;
46+
}
47+
]]></css>
3648
<height>150</height>
37-
<html><![CDATA[<div>first</div>
38-
<div>sibling<div>child</div></div>
39-
<div>sibling</div>
40-
41-
<div>sibling</div>]]></html>
49+
<html><![CDATA[
50+
<div>first</div>
51+
<div>sibling<div>child</div></div>
52+
<div>sibling</div>
53+
<div>sibling</div>]]></html>
4254
</example>
4355
<example>
4456
<desc>Locate all the paragraphs after the second child in the body and give them a class.</desc>
4557
<code><![CDATA[
46-
$(":nth-child(1)").nextAll("p").addClass("after");
58+
$( ":nth-child(1)" ).nextAll( "p" ).addClass( "after" );
4759
]]></code>
4860
<css><![CDATA[
49-
div, p { width: 60px; height: 60px; background: #abc;
50-
border: 2px solid black; margin: 10px; float: left; }
51-
.after { border-color: red; }
61+
div, p {
62+
width: 60px;
63+
height: 60px;
64+
background: #abc;
65+
border: 2px solid black;
66+
margin: 10px;
67+
float: left;
68+
}
69+
.after {
70+
border-color: red;
71+
}
5272
]]></css>
5373
<height>200</height>
54-
<html><![CDATA[<p>p</p>
74+
<html><![CDATA[
75+
<p>p</p>
5576
<div>div</div>
5677
<p>p</p>
5778
<p>p</p>
5879
<div>div</div>
59-
6080
<p>p</p>
61-
<div>div</div>]]></html>
81+
<div>div</div>
82+
]]></html>
6283
</example>
6384
<category slug="traversing/tree-traversal"/>
6485
<category slug="version/1.2"/>
65-
</entry>
86+
</entry>

entries/nextUntil.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,32 @@
3030
<height>250px</height>
3131
<desc>Find the siblings that follow &lt;dt id="term-2"&gt; up to the next &lt;dt&gt; and give them a red background color. Also, find &lt;dd&gt; siblings that follow &lt;dt id="term-1"&gt; up to &lt;dt id="term-3"&gt; and give them a green text color. </desc>
3232
<code><![CDATA[
33-
$("#term-2").nextUntil("dt")
34-
.css("background-color", "red");
35-
36-
var term3 = document.getElementById("term-3");
37-
$("#term-1").nextUntil(term3, "dd")
38-
.css("color", "green");
39-
33+
$( "#term-2" )
34+
.nextUntil( "dt" )
35+
.css( "background-color", "red" );
36+
var term3 = document.getElementById( "term-3" );
37+
$( "#term-1" )
38+
.nextUntil( term3, "dd" )
39+
.css( "color", "green" );
4040
]]></code>
41-
<html><![CDATA[<dl>
41+
<html><![CDATA[
42+
<dl>
4243
<dt id="term-1">term 1</dt>
4344
<dd>definition 1-a</dd>
4445
<dd>definition 1-b</dd>
4546
<dd>definition 1-c</dd>
4647
<dd>definition 1-d</dd>
47-
4848
<dt id="term-2">term 2</dt>
4949
<dd>definition 2-a</dd>
5050
<dd>definition 2-b</dd>
5151
<dd>definition 2-c</dd>
52-
5352
<dt id="term-3">term 3</dt>
5453
<dd>definition 3-a</dd>
5554
<dd>definition 3-b</dd>
56-
</dl>]]></html>
55+
</dl>
56+
]]></html>
5757
</example>
5858
<category slug="traversing/tree-traversal"/>
5959
<category slug="version/1.4"/>
6060
<category slug="version/1.6"/>
61-
</entry>
61+
</entry>

entries/not-selector.xml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,24 @@
1717
<example>
1818
<desc>Finds all inputs that are not checked and highlights the next sibling span. Notice there is no change when clicking the checkboxes since no click events have been linked.</desc>
1919
<code><![CDATA[
20-
$("input:not(:checked) + span").css("background-color", "yellow");
21-
$("input").attr("disabled", "disabled");
22-
20+
$( "input:not(:checked) + span" ).css( "background-color", "yellow" );
21+
$( "input").attr("disabled", "disabled" );
2322
]]></code>
24-
<html><![CDATA[<div>
25-
<input type="checkbox" name="a" />
23+
<html><![CDATA[
24+
<div>
25+
<input type="checkbox" name="a">
2626
<span>Mary</span>
2727
</div>
28-
2928
<div>
30-
<input type="checkbox" name="b" />
29+
<input type="checkbox" name="b">
3130
<span>lcm</span>
32-
3331
</div>
3432
<div>
35-
<input type="checkbox" name="c" checked="checked" />
36-
33+
<input type="checkbox" name="c" checked="checked">
3734
<span>Peter</span>
38-
</div>]]></html>
35+
</div>
36+
]]></html>
3937
</example>
4038
<category slug="selectors/basic-filter-selectors"/>
4139
<category slug="version/1.0"/>
42-
</entry>
40+
</entry>

entries/not.xml

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737
&lt;li&gt;list item 4&lt;/li&gt;
3838
&lt;li&gt;list item 5&lt;/li&gt;
3939
&lt;/ul&gt;
40-
</code></pre>
40+
</code></pre>
4141
<p>We can apply this method to the set of list items:</p>
42-
<pre><code>$('li').not(':even').css('background-color', 'red');</code></pre>
42+
<pre><code>
43+
$( "li" ).not( ":even" ).css( "background-color", "red" );
44+
</code></pre>
4345
<p>The result of this call is a red background for items 2 and 4, as they do not match the selector (recall that :even and :odd use 0-based indexing).</p>
4446
<h4>Removing Specific Elements</h4>
4547
<p>The second version of the <code>.not()</code> method allows us to remove elements from the matched set, assuming we have found those elements previously by some other means. For example, suppose our list had an id applied to one of its items:</p>
@@ -51,53 +53,70 @@
5153
&lt;li&gt;list item 4&lt;/li&gt;
5254
&lt;li&gt;list item 5&lt;/li&gt;
5355
&lt;/ul&gt;
54-
</code></pre>
56+
</code></pre>
5557
<p>We can fetch the third list item using the native JavaScript <code>getElementById()</code> function, then remove it from a jQuery object:</p>
5658
<pre><code>
57-
$('li').not(document.getElementById('notli'))
58-
.css('background-color', 'red');
59-
</code></pre>
59+
$( "li" ).not( document.getElementById( "notli" ) )
60+
.css( "background-color", "red" );
61+
</code></pre>
6062
<p>This statement changes the color of items 1, 2, 4, and 5. We could have accomplished the same thing with a simpler jQuery expression, but this technique can be useful when, for example, other libraries provide references to plain DOM nodes.</p>
6163
<p>As of jQuery 1.4, the <code>.not()</code> method can take a function as its argument in the same way that <code>.filter()</code> does. Elements for which the function returns <code>true</code> are excluded from the filtered set; all other elements are included.</p>
6264
</longdesc>
6365
<example>
6466
<desc>Adds a border to divs that are not green or blue.</desc>
6567
<code><![CDATA[
66-
$("div").not(".green, #blueone")
67-
.css("border-color", "red");
68-
68+
$( "div" ).not( ".green, #blueone" )
69+
.css( "border-color", "red" );
6970
]]></code>
7071
<css><![CDATA[
71-
div { width:50px; height:50px; margin:10px; float:left;
72-
background:yellow; border:2px solid white; }
73-
.green { background:#8f8; }
74-
.gray { background:#ccc; }
75-
#blueone { background:#99f; }
72+
div {
73+
width: 50px;
74+
height: 50px;
75+
margin: 10px;
76+
float: left;
77+
background: yellow;
78+
border: 2px solid white;
79+
}
80+
.green {
81+
background: #8f8;
82+
}
83+
.gray {
84+
background: #ccc;
85+
}
86+
#blueone {
87+
background: #99f;
88+
}
7689
]]></css>
77-
<html><![CDATA[<div></div>
90+
<html><![CDATA[
91+
<div></div>
7892
<div id="blueone"></div>
7993
<div></div>
8094
<div class="green"></div>
81-
8295
<div class="green"></div>
8396
<div class="gray"></div>
8497
<div></div>
8598
]]></html>
8699
</example>
87100
<example>
88101
<desc>Removes the element with the ID "selected" from the set of all paragraphs.</desc>
89-
<code><![CDATA[$("p").not( $("#selected")[0] )]]></code>
102+
<code><![CDATA[
103+
$( "p" ).not( $( "#selected" )[ 0 ] );
104+
]]></code>
90105
</example>
91106
<example>
92107
<desc>Removes the element with the ID "selected" from the set of all paragraphs.</desc>
93-
<code><![CDATA[$("p").not("#selected")]]></code>
108+
<code><![CDATA[
109+
$( "p" ).not( "#selected" );
110+
]]></code>
94111
</example>
95112
<example>
96113
<desc>Removes all elements that match "div p.selected" from the total set of all paragraphs.</desc>
97-
<code><![CDATA[$("p").not($("div p.selected"))]]></code>
114+
<code><![CDATA[
115+
$( "p" ).not( $( "div p.selected" ) );
116+
]]></code>
98117
</example>
99118
<category slug="traversing/filtering"/>
100119
<category slug="traversing/miscellaneous-traversal"/>
101120
<category slug="version/1.0"/>
102121
<category slug="version/1.4"/>
103-
</entry>
122+
</entry>

0 commit comments

Comments
 (0)