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/eq-selector.xml
+37-6Lines changed: 37 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,25 @@
1
1
<?xml version="1.0"?>
2
2
<entrytype="selector"name="eq"return="">
3
3
<title>:eq() Selector</title>
4
-
<sample>:eq(index)</sample>
5
4
<signature>
5
+
<sample>:eq(index)</sample>
6
6
<added>1.0</added>
7
7
<argumentname="index"type="Number">
8
8
<desc>Zero-based index of the element to match.</desc>
9
9
</argument>
10
10
</signature>
11
+
<signature>
12
+
<sample>:eq(-index)</sample>
13
+
<added>1.8</added>
14
+
<argumentname="-index"type="Integer">
15
+
<desc>Zero-based index of the element to match, counting backwards from the last element. </desc>
16
+
</argument>
17
+
</signature>
11
18
<desc>Select the element at index <code>n</code> within the matched set.</desc>
12
19
<longdesc>
13
20
<p>The index-related selectors (<code>:eq()</code>, <code>:lt()</code>, <code>:gt()</code>, <code>:even</code>, <code>:odd</code>) filter the set of elements that have matched the expressions that precede them. They narrow the set down based on the order of the elements within this matched set. For example, if elements are first selected with a class selector (<code>.myclass</code>) and four elements are returned, these elements are given indices <code>0</code> through <code>3</code> for the purposes of these selectors.</p>
14
21
<p>Note that since JavaScript arrays use <em>0-based indexing</em>, these selectors reflect that fact. This is why <code>$('.myclass:eq(1)')</code> selects the second element in the document with the class myclass, rather than the first. In contrast, <code>:nth-child(n)</code> uses <em>1-based indexing</em> to conform to the CSS specification.</p>
15
-
<p>Unlike the <ahref="http://api.jquery.com/eq/"><code>.eq(index)</code></a> method, the <code>:eq(index)</code> selector does <em>not</em> accept a negative value for <code>index</code>. For example, while <code>$('li').eq(-1)</code> selects the last <code>li</code> element, <code>$('li:eq(-1)')</code> selects nothing.</p>
22
+
<p>Prior to jQuery 1.8, the <code>:eq(index)</code> selector did <em>not</em> accept a negative value for <code>index</code> (though the <ahref="/eq/"><code>.eq(index)</code></a> method did).</p>
<desc>Apply three different styles to list items to demonstrate that <code>:eq()</code> is designed to select a single element while <code>:nth-child()</code> or <code>:eq()</code> within a looping construct such as <code>.each()</code> can select multiple elements.</desc>
30
37
<code><![CDATA[
31
-
// applies yellow background color to a single <li>
38
+
/* applies yellow background color to a single <li> */
0 commit comments