jQuery :eq() Selector

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

What Is the :eq() Selector?

:eq(index) (since jQuery 1.0) selects the single element at a zero-based index in the matched set. Negative indices (from the end) are supported since 1.8.

Remember
$("td:eq(2)");              // third cell (index 2)
$("li:eq(0)");              // first list item
$("li:eq(-2)");             // second-to-last (since 1.8)

// Preferred today (jQuery 3.4+):
$("td").eq(2);              // same as :eq(2)
NeedUse
Exactly one index$("el").eq(n) · legacy $("el:eq(n)")
Elements before index n:lt(n) · .slice(0, n)
Elements after index n:gt(n) · .slice(n + 1)
Even / odd positions:even / :odd
CSS nth child (1-based):nth-child()

How to Use :eq()

Build a matched set first, then pick one item by index — or migrate to .eq().

  1. Select a set ($("td"), $("li"), …).
  2. Choose a zero-based index (or a negative index from the end).
  3. Legacy: append :eq(index) · Modern: call .eq(index).
  4. Remember: one match only — not every “nth” across parents.
  5. For per-list “second item”, loop with .each() and .eq(1) inside.
PieceRequired?Role
Preceding selectorYesBuilds the set that :eq / .eq filters
indexYesZero-based position in that set
Negative indexNoSince 1.8 — count from the end
Return value—jQuery set with 0 or 1 element

Pseudocode

Pseudocode
set = $(precedingSelector)   // indices 0 … length-1

call set.filter(":eq(index)")
  // or set.eq(index)

if index is negative:
    index = set.length + index   // e.g. -1 → last

if 0 <= index < set.length:
    return set[index] as a jQuery object
else:
    return empty jQuery set

Cheat Sheet

Keep these facts handy while picking by index.

TopicDetail
Syntax$("sel:eq(index)")
Since1.0 · negative index since 1.8
DeprecatedjQuery 3.4 — prefer .eq()
Migration:eq(n) → .eq(n)
Indexing0-based (like JS arrays)
MatchesAt most one element
vs :nth-childSet position (0-based) vs parent child (1-based CSS)
Out of rangeEmpty set — length 0

Live Preview

Highlight one table cell with :eq() or the modern .eq() equivalent.

TD #0TD #1TD #2
TD #3TD #4TD #5
TD #6TD #7TD #8

Yellow cell is the match. :eq(2) and .eq(2) select the same cell.

Result
Ready — click Run to pick a cell.

jQuery Examples

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

Example 1 — Official td:eq(2)

From the jQuery docs: pick the third table cell.

jQuery
var text = $("td:eq(2)").text();
$("#out").text("Matched: " + text + " (index 2)");
Try It Yourself

How It Works

  1. Set. All td cells get indices 0–8.
  2. eq(2). Keeps only the third cell.
  3. text. Reads that cell’s label.
  4. Report. Shows which index was selected.

Example 2 — Modern .eq(2)

Same cell as :eq(2) — the recommended jQuery 3.4+ replacement.

jQuery
$("#out").text(
  ":eq(2) → " + $("td:eq(2)").text() + "\n" +
  ".eq(2) → " + $("td").eq(2).text()
);
Try It Yourself

How It Works

  1. Rule. :eq(n) ↔ .eq(n).
  2. Select. Pure CSS $("td") can use querySelectorAll.
  3. Filter. .eq(2) picks index 2 afterward.
  4. Future-proof. Avoids the deprecated pseudo-class.

Example 3 — Negative Index :eq(-2)

Count from the end (since 1.8) to pick the second-to-last item.

jQuery
$("#out").text(
  "eq(-2) → " + $("li:eq(-2)").text() + "\n" +
  ".eq(-2) → " + $("li").eq(-2).text()
);
Try It Yourself

How It Works

  1. Set. Six list items → indices 0–5.
  2. -2. Means second-to-last (index 4).
  3. Match. Official demo targets “List 2, item 2”.
  4. .eq(-2). Same result without :eq.

Example 4 — :eq() vs :nth-child()

One set index versus every second child of its parent.

jQuery
$("#out").text(
  ":eq(1) → " + $("ul.nav li:eq(1)").text() + "\n" +
  ":nth-child(2) → " + $("ul.nav li:nth-child(2)").map(function () {
    return $(this).text();
  }).get().join(" | ")
);
Try It Yourself

How It Works

  1. eq(1). Second item in the whole li set — one match.
  2. nth-child(2). Every li that is child #2 of its ul.
  3. Count. One vs many — different indexing models.
  4. Remember. :eq is 0-based; :nth-child is 1-based CSS.

Example 5 — Second Item in Each List

Official pattern: loop lists, then pick li:eq(1) inside each.

jQuery
var lines = [];
$("ul.nav").each(function () {
  lines.push($(this).find("li").eq(1).text());
});
$("#out").text(lines.join("\n"));
Try It Yourself

How It Works

  1. each. Visits every ul.nav.
  2. find + eq. Second li inside that list.
  3. Collect. Two matches — one per list.
  4. Why. Bare $("li:eq(1)") would only hit the second item globally.

Edge Cases & Pitfalls

Check these before relying on :eq() in real pages.

index

:eq(1) is the second element

Zero-based like JS arrays. The first match is :eq(0), not :eq(1).

nth

Not the same as :nth-child

Set position vs parent child; 0-based vs 1-based. They often pick different elements.

3.4+

Deprecated since jQuery 3.4

Still works today, but new code should use $("sel").eq(n).

scope

One match for the whole set

Need “second in each list”? Loop with .each() and .eq(1) inside each parent.

Browser Support

:eq() has been part of jQuery since 1.0 (negative indices since 1.8). It still works, but is deprecated since jQuery 3.4 — prefer .eq() for new code.

✓ Deprecated · jQuery 1.0+

jQuery :eq()

Works across jQuery 1.x–3.x where loaded, but avoid in new projects. Migrate to $("sel").eq(n) for better performance and future compatibility.

Legacy Status
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() Deprecated 3.4+

Bottom line: Fine for reading older tutorials. For production on jQuery 3.4+, use .eq() instead of :eq().

Performance Notes

ApproachCostBest for
$("css").eq(n)BestModern browsers + jQuery 3.4+
$("el:eq(n)")SlowerLegacy code only — no querySelectorAll
Huge lists filtered oftenCan add upCache the set; call .eq() once

Because :eq() is a jQuery extension, the engine cannot hand the whole query to the browser. Select with CSS, then .eq(), for the fastest path.

Key Takeaways

  • Role: pick exactly one item by 0-based index — since jQuery 1.0.
  • Migrate: :eq(n) → .eq(n) (deprecated 3.4).
  • vs nth: set index (0-based) ≠ CSS :nth-child (1-based).
  • Negative: :eq(-2) since 1.8 · or .eq(-2) for the same.

One line: :eq(n) picks one element at index n — prefer .eq(n) in modern jQuery.

Frequently Asked Questions

:eq(index) selects the single element at a zero-based index within the matched set. $("td:eq(2)") picks the third td (index 2). Available since jQuery 1.0; negative indices since 1.8.
Yes — deprecated in jQuery 3.4. Official docs recommend removing :eq() from selectors and filtering later with .eq(): $("td").eq(2) replaces $("td:eq(2)").
:eq() filters the jQuery matched set by 0-based position after the preceding selector. :nth-child(n) is CSS — it picks elements that are the nth child of their parent (1-based). $(".myclass:eq(1)") is the second .myclass in the set; :nth-child(1) means first child of its parent.
Since jQuery 1.8, :eq(-index) counts backwards from the last element. $("li:eq(-2)") selects the second-to-last list item. Prefer $("li").eq(-2) in new code.
Official docs: :eq() is a jQuery extension and cannot use native querySelectorAll. $("your-pure-css-selector").eq(index) is faster in modern browsers and avoids the deprecated pseudo-class.
No — :eq() always returns at most one element from the current matched set. To style the second item in each list, loop with .each() and call .eq(1) (or find("li").eq(1)) inside each list.

Next: :lt() Selector

Select every element before a zero-based index in the matched set.

:lt() 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.

10 people found this page helpful