jQuery .eq() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Traversing

Definition

.eq(index) (since jQuery 1.1.2) reduces the matched set to one element at a zero-based position. Negative indexes (since 1.4) count from the end. Out of range → empty set (length 0).

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("li").eq(2)      // 3rd item (official)
$("li").eq(-2)     // 2nd from last (jQuery 1.4+)
$("li").eq(0)      // same idea as .first()
$("li").eq(-1)     // same idea as .last()
$("li").eq(99)     // empty set — safe, no throw

// Returns a jQuery object (keep chaining)
// .get(n) returns a raw DOM node instead
CallWhat it does
Matched setCollection to reduce
index0-based from start (1.1.2+)
indexFromEndNegative from end (1.4+)
Return valueNew jQuery set (0 or 1 element)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select a collection (e.g. $("li") or $("div.box")).
Step 2Call .eq(n) with a zero-based index.
Step 3Or use a negative index from the end (jQuery 1.4+).

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Official: $("li").eq(2)

Mark the third list item (zero-based index 2).

jQuery
$("li").eq(2).append(" [eq(2)]");
Try It Yourself

How It Works

  1. Select. Collect every li.
  2. Index. 2 means the third item (0, 1, 2).
  3. Reduce. The set becomes that one element.

Example 2 — Official: .eq(-2) From the End

Negative indexes count backwards (jQuery 1.4+).

jQuery
$("li").eq(-2).append(" [eq(-2)]");
Try It Yourself

How It Works

  1. From end. -1 is last; -2 is second from last.
  2. Resolve. For five items, -2 → index 3.
  3. Result. Item 4 is marked.

Example 3 — Official: find("div").eq(2)

Index applies to the matched divs in document order.

jQuery
$("#eq-demo").find("div").eq(2).append(" [blue]");
Try It Yourself

How It Works

  1. find. Collect every div under the demo root.
  2. Order. Positions follow document order in that set.
  3. eq(2). Keeps the third matched div.

Frequently Asked Questions

.eq(index) reduces the matched set to the single element at that zero-based position. It returns a new jQuery object with one element — or an empty set if the index is out of range. Available since jQuery 1.1.2; negative indexes since 1.4.
Yes. .eq(0) is the first element in the current jQuery set, .eq(1) the second. The index is within the collection, not the whole DOM tree.
Since jQuery 1.4, .eq(-1) is the last element, .eq(-2) is second from last — counting backwards from the end of the set.
You get an empty jQuery object (length 0). Chained methods do nothing; no error is thrown.
.eq() returns a jQuery object so you can keep chaining. .get(index) returns a raw DOM element (or undefined).
.first() is like .eq(0). .last() is like .eq(-1). Use .eq(n) when you need any middle index.

Next: .slice() Method

Keep a contiguous range of elements from the matched set.

.slice() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful