jQuery .eq() Method

Beginner
5 min read
Updated: Oct 2026
5 examples
Live preview

What Is .eq()?

.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).

Remember
$("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
NeedUse
One item by index$set.eq(n)
First / last.first() / .last()
A range of items.slice(start, end)
Raw DOM node.get(n) (not a jQuery object)
Keep matching many.filter()

How to Use .eq()

Build a set, then pick one position from that set.

  1. Select a collection (e.g. $("li") or $("div.box")).
  2. Call .eq(n) with a zero-based index.
  3. Or use a negative index from the end (jQuery 1.4+).
  4. Chain methods on the one-element set — or check .length if it might be empty.
  5. Remember: the index is inside the current set, not the whole document.
PieceRequired?Role
Matched setYesCollection to reduce
indexYes0-based from start (1.1.2+)
indexFromEndAlt formNegative from end (1.4+)
Return value—New jQuery set (0 or 1 element)

Pseudocode

Pseudocode
call $(set).eq(index)

if index < 0:
    index = set.length + index   // from the end

if 0 ≤ index < set.length:
    return new jQuery object with set[index]
else:
    return empty jQuery object (length 0)

Cheat Sheet

Index shortcuts side by side.

TopicDetail
Syntax.eq(index)
Since1.1.2 · negative in 1.4
.eq(0)≈ .first()
.eq(-1)≈ .last()
Out of rangeEmpty set — no throw
vs .get(n)jQuery object vs DOM node
vs .slice()One item vs a range

Live Preview

Pick a list item by index — including negative positions from the end.

  • list item 1
  • list item 2
  • list item 3
  • list item 4
  • list item 5

Official idea: .eq(2) is the third item (zero-based). .eq(-2) is two from the end.

Result
Ready — choose a call and click Run.

jQuery Examples

Short, copy-ready snippets. Open DevTools, or use Try It Yourself for a live editor.

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.
  4. Mark. Only item 3 gets the suffix.

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.
  4. Use. Handy when you know “near the end” but not the length.

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.
  4. Mark. Only that box gets the suffix.

Example 4 — Out of Range → Empty Set

No match? Safe empty object — no exception.

jQuery
var $hit = $("li").eq(5);
$("#out").text("length: " + $hit.length);
$hit.append(" [never]");
Try It Yourself

How It Works

  1. Five items. Valid indexes are 0–4.
  2. eq(5). Asks for a sixth item — none exists.
  3. Empty. .length is 0.
  4. Safe chain. .append() on an empty set does nothing.

Example 5 — .eq() vs .first() / .last()

Same ends of the set — different APIs.

jQuery
$("li").eq(0).append(" [eq0]");
$("li").first().append(" [first]");
$("li").eq(-1).append(" [eq-1]");
$("li").last().append(" [last]");
Try It Yourself

How It Works

  1. Start. .eq(0) and .first() target the same element.
  2. End. .eq(-1) and .last() target the same element.
  3. Middle. Only .eq(n) picks an arbitrary middle index.
  4. Style. Prefer .first()/.last() when the intent is “ends only.”

Edge Cases & Pitfalls

Index mistakes that pick the wrong node — or none.

zero

Off-by-one

Humans count from 1; .eq() counts from 0. The “third” item is .eq(2).

set

Index is in the collection

After $("ul li"), indexes follow that filtered list — not every node on the page.

empty

Out of range is silent

Official behavior: empty set, length 0. Check length when a miss matters.

get

.eq() ≠ .get()

.get(n) returns a DOM element. Calling .append() on it fails — wrap with $() or use .eq().

Browser Support

.eq() has been part of jQuery since 1.1.2. Negative indexes arrived in 1.4. It works in every browser that runs your loaded jQuery version.

✓ Stable · jQuery 1.1.2+

jQuery .eq()

Supported across jQuery 1.x, 2.x, and 3.x. Prefer .eq(n) for one item; use .slice() for ranges and .first()/.last() for ends.

100% With jQuery
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
.eq() Universal

Bottom line: Safe for picking one element by index. Remember zero-based positions, negative from-end indexes, and empty sets out of range.

Performance Notes

ApproachCostBest for
.eq(n)CheapOne item from an existing set
.first() / .last()SameClearer intent at the ends
.slice(n, n + 1)OKPrefer .eq(n) instead
Narrower start setFasterPrefer $("ul li") over $("*")

.eq() is a thin reduce — cost is dominated by how large the starting selection is. Scope first, then pick by index.

Key Takeaways

  • Role: reduce the set to one element by index.
  • Zero-based: third item → .eq(2); last → .eq(-1).
  • Miss: out of range → empty set, no throw.
  • Next: .slice() for a range of indexes.

One line: .eq(n) keeps one element from the current set — count from zero, or from the end with a negative index.

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() tutorial →

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