jQuery :eq() Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

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

Syntax

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

jQuery
$("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)
CallWhat it does
Preceding selectorBuilds the set that :eq / .eq filters
indexZero-based position in that set
Negative indexSince 1.8 — count from the end
Return valuejQuery set with 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 set ($("td"), $("li"), …).
Step 2Choose a zero-based index (or a negative index from the end).
Step 3Legacy: append :eq(index) · Modern: call .eq(index).

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

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.

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.

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

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

10 people found this page helpful