Latest web development tutorials

jQuery eq () method

jQuery traversal methods jQuery traversal methods

Examples

Select the second <p> element (index number 1):

$("p").eq(1).css("background-color","yellow");

try it"

Definition and Usage

eq () method returns the element with the specified index number of the selected element.

From the beginning of the index number 0, so the index number of the first element is 0 (not 1).


grammar

$(selector).eq( index )

参数 描述
index 必需。规定元素的索引。可以是整数或负数。

注意:使用负数将从被选元素的结尾开始计算索引。

Examples

More examples

Use negative
Use negative returns the second <p> element from the end of the selected element.


jQuery traversal methods jQuery traversal methods