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
Copy file name to clipboardExpand all lines: entries/each.xml
+94-68
Original file line number
Diff line number
Diff line change
@@ -11,16 +11,18 @@
11
11
<longdesc>
12
12
<p>The <code>.each()</code> method is designed to make DOM looping constructs concise and less error-prone. When called it iterates over the DOM elements that are part of the jQuery object. Each time the callback runs, it is passed the current loop iteration, beginning from 0. More importantly, the callback is fired in the context of the current DOM element, so the keyword <code>this</code> refers to the element.</p>
13
13
<p>Suppose you have a simple unordered list on the page:</p>
14
-
<pre><code><ul>
15
-
<li>foo</li>
16
-
<li>bar</li>
14
+
<pre><code>
15
+
<ul>
16
+
<li>foo</li>
17
+
<li>bar</li>
17
18
</ul>
18
19
</code></pre>
19
20
<p>You can select the list items and iterate across them:</p>
20
-
<pre><code>$( "li" ).each(function( index ) {
21
-
console.log( index + ": " + $(this).text() );
21
+
<pre><code>
22
+
$( "li" ).each(function( index ) {
23
+
console.log( index + ": " + $( this ).text() );
22
24
});
23
-
</code></pre>
25
+
</code></pre>
24
26
<p>A message is thus logged for each item in the list:</p>
25
27
<p>
26
28
<samp>0: foo</samp>
@@ -29,9 +31,10 @@
29
31
</p>
30
32
<p>You can stop the loop from within the callback function by returning <code>false</code>.</p>
31
33
<p>Note: most jQuery methods that return a jQuery object also loop through the set of elements in the jQuery collection — a process known as <i>implicit iteration</i>. When this occurs, it is often unnecessary to <i>explicitly</i> iterate with the <code>.each()</code> method:</p>
32
-
<pre><code>// The .each() method is unnecessary here:
34
+
<pre><code>
35
+
// The .each() method is unnecessary here:
33
36
$( "li" ).each(function() {
34
-
$(this).addClass( "foo" );
37
+
$(this).addClass( "foo" );
35
38
});
36
39
37
40
// Instead, you should rely on implicit iteration:
@@ -41,79 +44,102 @@ $( "li" ).addClass( "bar" );
41
44
<example>
42
45
<desc>Iterate over three divs and sets their color property.</desc>
43
46
<code><![CDATA[
44
-
$(document.body).click(function () {
45
-
$( "div" ).each(function (i) {
46
-
if ( this.style.color != "blue" ) {
47
-
this.style.color = "blue";
48
-
} else {
49
-
this.style.color = "";
50
-
}
51
-
});
52
-
});
47
+
$( document.body).click(function () {
48
+
$( "div" ).each(function ( i ) {
49
+
if ( this.style.color != "blue" ) {
50
+
this.style.color = "blue";
51
+
} else {
52
+
this.style.color = "";
53
+
}
54
+
});
55
+
});
53
56
]]></code>
54
57
<css><![CDATA[
55
-
div { color:red; text-align:center; cursor:pointer;
56
-
font-weight:bolder; width:300px; }
57
-
]]></css>
58
-
<html><![CDATA[<div>Click here</div>
59
-
<div>to iterate through</div>
60
-
<div>these divs.</div>]]></html>
58
+
div {
59
+
color: red;
60
+
text-align: center;
61
+
cursor: pointer;
62
+
font-weight: bolder;
63
+
width: 300px;
64
+
}
65
+
]]></css>
66
+
<html><![CDATA[
67
+
<div>Click here</div>
68
+
<div>to iterate through</div>
69
+
<div>these divs.</div>
70
+
]]></html>
61
71
</example>
62
72
<example>
63
-
<desc>To access a jQuery object instead of the regular DOM element, use <code>$(this)</code>. For example:</desc>
73
+
<desc>To access a jQuery object instead of the regular DOM element, use <code>$(this)</code>. For example:</desc>
Copy file name to clipboardExpand all lines: entries/empty.xml
+22-12
Original file line number
Diff line number
Diff line change
@@ -7,37 +7,47 @@
7
7
<desc>Remove all child nodes of the set of matched elements from the DOM.</desc>
8
8
<longdesc>
9
9
<p>This method removes not only child (and other descendant) elements, but also any text within the set of matched elements. This is because, according to the DOM specification, any string of text within an element is considered a child node of that element. Consider the following HTML:</p>
10
-
<pre><code><div class="container">
10
+
<pre><code>
11
+
<div class="container">
11
12
<div class="hello">Hello</div>
12
13
<div class="goodbye">Goodbye</div>
13
-
</div></code></pre>
14
+
</div>
15
+
</code></pre>
14
16
<p>We can target any element for removal:</p>
15
-
<pre><code>$('.hello').empty();</code></pre>
17
+
<pre><code>
18
+
$( ".hello" ).empty();
19
+
</code></pre>
16
20
<p>This will result in a DOM structure with the <code>Hello</code> text deleted:</p>
17
-
<pre><code><div class="container">
21
+
<pre><code>
22
+
<div class="container">
18
23
<div class="hello"></div>
19
24
<div class="goodbye">Goodbye</div>
20
-
</div></code></pre>
25
+
</div>
26
+
</code></pre>
21
27
<p>If we had any number of nested elements inside <code><div class="hello"></code>, they would be removed, too. </p>
22
28
<p>To avoid memory leaks, jQuery removes other constructs such as data and event handlers from the child elements before removing the elements themselves.</p>
23
29
<p>If you want to remove elements without destroying their data or event handlers (so they can be re-added later), use <ahref="/detach/"><code>.detach()</code></a> instead.</p>
24
30
</longdesc>
25
31
<example>
26
32
<desc>Removes all child nodes (including text nodes) from all paragraphs</desc>
Copy file name to clipboardExpand all lines: entries/enabled-selector.xml
+10-7
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@
7
7
</signature>
8
8
<desc>Selects all elements that are enabled.</desc>
9
9
<longdesc>
10
-
<p>As with other pseudo-class selectors (those that begin with a ":") it is recommended to precede it with a tag name or some other selector; otherwise, the universal selector ("*") is implied. In other words, the bare <code>$(':enabled')</code> is equivalent to <code>$('*:enabled')</code>, so <code>$('input:enabled')</code> or similar should be used instead. </p>
10
+
<p>As with other pseudo-class selectors (those that begin with a ":") it is recommended to precede it with a tag name or some other selector; otherwise, the universal selector ("*") is implied. In other words, the bare <code>$( ":enabled" )</code> is equivalent to <code>$( "*:enabled" )</code>, so <code>$( "input:enabled" )</code> or similar should be used instead. </p>
11
11
12
12
<p>Although their resulting selections are usually the same, <code>:enabled</code> selector is subtly different from <code>:not([disabled])</code>; <code>:enabled</code> selects elements that have their boolean disabled property strictly equal to false, while <code>:not([disabled])</code> selects elements that do not have a disabled <em>attribute</em> set (regardless of its value).</p>
13
13
@@ -16,12 +16,15 @@
16
16
</longdesc>
17
17
<example>
18
18
<desc>Find all input elements that are enabled.</desc>
19
-
<code><![CDATA[$("input:enabled").val("this is it");]]></code>
0 commit comments