jQuery eq() method
Example
Select the second
element (with index number 1):
$("p").eq(1).css("background-color","yellow");
Try it »
Definition and Usage
The eq() method returns the element with the specified index number among the selected elements.
Index numbers start at 0, so the first element has index number 0 (not 1).
Syntax
$(
selector
).eq(
index
)
| Parameters | Description |
|---|---|
| index | Required. Specifies the index of the element. It can be an integer or a negative number. |
**注意:**使用负数将从被选元素的结尾开始计算索引。 |
More examples
Using negative numbers
Using a negative number to return the second from the end of the selected elements
.
jQuery Traversal Methods