jQuery :even Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

:even (since jQuery 1.0) selects elements at zero-based even indices in the matched set — 0, 2, 4, …. That means the first, third, fifth, and so on. Partner of :odd.

Syntax

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

jQuery
$("tr:even");               // rows at indices 0, 2, 4 …
$("li:even");               // first, third, fifth items
$("td:even");               // even cells in document order

// Preferred today (jQuery 3.5+):
$("tr").even();             // same as :even
CallWhat it does
Preceding selectorBuilds the set that :even / .even filters
Indexing0-based positions in that set (document order)
MatchesIndices where i % 2 === 0
Return valuejQuery set of even-indexed elements

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

Parameters

ParameterDescription
Step 1Select a set ($("tr"), $("li"), …).
Step 2Remember: index 0 is even — the first item matches.
Step 3Legacy: append :even · Modern: call .even() (3.5+).

Return Value

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

jQuery Examples

Example 1 — Official tr:even

From the jQuery docs: match the first, third, and so on table rows.

jQuery
var rows = $("tr:even").map(function () {
  return $(this).text().trim();
}).get();
$("#out").text("Even rows:\n" + rows.join("\n"));
Try It Yourself

How It Works

  1. Set. All tr rows get indices 0–3.
  2. even. Keeps only indices where i % 2 === 0.
  3. map. Collects each matched row’s text.

Example 2 — Modern .even()

Same rows as :even — the recommended jQuery 3.5+ replacement.

jQuery
$("#out").text(
  ":even → " + $("tr:even").length + "\n" +
  ".even() → " + $("tr").even().length
);
Try It Yourself

How It Works

  1. Rule. :even ↔ .even() (since 3.5).
  2. Select. Pure CSS $("tr") can use querySelectorAll.
  3. Filter. .even() keeps even indices afterward.

Example 3 — :even vs :odd

Split the set into complementary halves with no overlap.

jQuery
$("#out").text(
  "even → " + $("tr:even").map(function () {
    return $(this).text().trim();
  }).get().join(", ") + "\n" +
  "odd → " + $("tr:odd").map(function () {
    return $(this).text().trim();
  }).get().join(", ")
);
Try It Yourself

How It Works

  1. even. Indices 0 and 2.
  2. odd. Indices 1 and 3.
  3. Cover. Together they match every row once.

Frequently Asked Questions

:even selects elements at zero-based even indices in the matched set — 0, 2, 4, and so on. $("tr:even") matches the first, third, and fifth rows. Available since jQuery 1.0.
Because indexing starts at 0. Index 0 is even, so the first element in the set is included. Official docs call this counter-intuitive if you expect “second, fourth…” like everyday counting.
Yes — deprecated in jQuery 3.4. Official docs recommend removing :even from selectors and filtering later with .even() (jQuery 3.5.0+): $("tr").even() replaces $("tr:even").
:even keeps indices 0, 2, 4…; :odd keeps 1, 3, 5…. Together they cover the whole matched set with no overlap.
Official docs: :even is a jQuery extension and cannot use native querySelectorAll. Select with a pure CSS selector first, then use .even() (3.5+) or .filter(":even") for better performance.
No — it filters the jQuery matched set by position in that set, in document order. It is not the same as CSS :nth-child(even), which is 1-based and parent-relative.

Next: :odd Selector

Select odd-indexed elements — the partner filter for zebra striping.

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