forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheq.xml
73 lines (73 loc) · 2.7 KB
/
eq.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?xml version="1.0"?>
<entry type="method" name="eq" return="jQuery">
<title>.eq()</title>
<signature>
<added>1.1.2</added>
<argument name="index" type="Integer">
<desc>An integer indicating the 0-based position of the element. </desc>
</argument>
</signature>
<signature>
<added>1.4</added>
<argument name="indexFromEnd" type="Integer">
<desc>An integer indicating the position of the element, counting backwards from the last element in the set. </desc>
</argument>
</signature>
<desc>Reduce the set of matched elements to the one at the specified index.</desc>
<longdesc>
<p>Given a jQuery object that represents a set of DOM elements, the <code>.eq()</code> method constructs a new jQuery object from one element within that set. The supplied index identifies the position of this element in the set. </p>
<p>Consider a page with a simple list on it:</p>
<pre><code>
<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
<li>list item 4</li>
<li>list item 5</li>
</ul>
</code></pre>
<p>We can apply this method to the set of list items:</p>
<pre><code>
$( "li" ).eq( 2 ).css( "background-color", "red" );
</code></pre>
<p>The result of this call is a red background for item 3. Note that the supplied index is zero-based, and refers to the position of the element within the jQuery object, not within the DOM tree.</p>
<p>Providing a negative number indicates a position starting from the end of the set, rather than the beginning. For example:</p>
<pre><code>
$( "li" ).eq( -2 ).css( "background-color", "red" );
</code></pre>
<p>This time list item 4 is turned red, since it is two from the end of the set.</p>
<p>If an element cannot be found at the specified zero-based index, the method constructs a new jQuery object with an empty set and a <code>length</code> property of 0. </p>
<pre><code>
$( "li" ).eq( 5 ).css( "background-color", "red" );
</code></pre>
<p>Here, none of the list items is turned red, since <code>.eq( 5 )</code> indicates the sixth of five list items.</p>
</longdesc>
<example>
<desc>Turn the div with index 2 blue by adding an appropriate class.</desc>
<code><![CDATA[
$( "body" ).find( "div" ).eq( 2 ).addClass( "blue" );
]]></code>
<css><![CDATA[
div {
width: 60px;
height: 60px;
margin: 10px;
float: left;
border: 2px solid blue;
}
.blue {
background: blue;
}
]]></css>
<html><![CDATA[
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
]]></html>
</example>
<category slug="traversing/filtering"/>
<category slug="version/1.1.2"/>
</entry>