← Back to Index

.eq()

Reduce the set of matched elements to the one at the specified index.

Examples

1. Positive Index

// <li>A</li><li>B</li><li>C</li>
$('li').eq(1).addClass('selected');

Result

<li>A</li>
<li class="selected">B</li>
<li>C</li>

2. Negative Index

$('li').eq(-1).addClass('last');

Result

<li>A</li>
<li>B</li>
<li class="last">C</li>

Parameters

Parameter Type Description
index number An integer indicating the 0-based position of the element. If negative, counts from the end of the set.

Returns: A new SR object.