jQuery :even Selector

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Index filter

What You’ll Learn

The :even selector matches elements at even zero-based indices in the matched set — index 0, 2, 4, and so on. Available since jQuery 1.0; pair with :odd; deprecated in jQuery 3.4 in favor of the .even() method (3.5+).

01

Syntax

tr:even

02

0-based

0, 2, 4…

03

Official

tr:even

04

vs :odd

1, 3, 5…

05

First row

Index 0 = even

06

.even()

Modern API

Introduction

Zebra-striped tables, alternating list backgrounds, and grid layouts often need every other element from a group. jQuery’s :even pseudo-class filters the matched set to elements at even positions using zero-based indexing.

Official jQuery documentation notes a common surprise: because index 0 is even, :even selects the first element, third element, fifth element, and so on — not the second, fourth, sixth as everyday “even row” counting might suggest. Index selectors (:eq(), :lt(), :gt(), :even, :odd) always follow another selector that builds the matched set.

Understanding the :even Selector

Think of :even as keeping every other slot starting at index 0:

  • tr:eq(0), tr:eq(2), tr:eq(4) → same indices as tr:even.
  • Four rows indexed 0–3 → :even matches rows 0 and 2 (first and third).
  • :odd matches the complement — indices 1 and 3 (second and fourth).
  • Selected elements stay in document order within the filtered set.
💡
Beginner Tip

For new code on jQuery 3.5+, prefer $("tr").even() over $("tr:even"). For performance with older patterns, use $("tr").filter(":even") after a pure CSS selector.

📝 Syntax

Official jQuery API form (since 1.0):

jQuery
jQuery( ":even" )



// typical usage — chain after a selector:

$( "tr:even" )

$( "li:even" )

$( "#salesTable tr:even" )



// modern replacement (jQuery 3.5+):

$( "tr" ).even()



// performance pattern:

$( "tr" ).filter( ":even" )

Parameters

  • No arguments — keeps elements at even 0-based indices in the matched set.

Return value

  • A jQuery object containing every even-indexed element (may be multiple).
  • Empty collection when the matched set has no even indices (rare — index 0 always matches if set is non-empty).

Official jQuery API example

jQuery
// Finds even table rows — index 0, 2, 4…

$( "tr:even" ).css( "background-color", "#bbf" );

⚡ Quick Reference

Index:even:odd
0 (first)MatchesNo match
1 (second)No matchMatches
2 (third)MatchesNo match
3 (fourth)No matchMatches
jQuery 3.5+.even().odd()

📋 :even vs :odd and CSS :nth-child

Index filters on the matched set vs child-position CSS.

:even
tr:even

Indices 0, 2, 4…

:odd
tr:odd

Indices 1, 3, 5…

.even()
$("tr").even()

Recommended 3.5+

nth-child
tr:nth-child(even)

CSS per parent

Examples Gallery

Example 1 follows the official jQuery tr:even demo. Examples 2–5 compare with :odd, scope to one table, use the modern .even() method, and apply the official .filter(":even") performance pattern.

📚 Official jQuery Demo

Zebra stripe even-indexed table rows — first, third, and so on.

Example 1 — Official Demo: tr:even

Official jQuery demo — light blue background on rows at index 0, 2, 4…

jQuery
$( "tr:even" ).css( "background-color", "#bbf" );



// Row #0 and #2 highlighted — Row #1 and #3 unchanged
Try It Yourself

How It Works

All tr elements are numbered 0-based in document order; :even keeps indices where index % 2 === 0.

Example 2 — :even vs :odd

Apply different styles to complementary index sets on the same list.

jQuery
$( "#list li:even" ).css( "backgroundColor", "#bbf" );

$( "#list li:odd" ).css( "color", "#dc2626" );



// :even → 3 items (0, 2, 4) · :odd → 2 items (1, 3)
Try It Yourself

How It Works

:even and :odd partition the matched set — every element matches exactly one of them.

📈 Practical Patterns

Scoping, modern API, and performance filtering.

Example 3 — Scoped Striping: $("#sales tr:even")

Stripe rows in one table without affecting others on the page.

jQuery
$( "#sales tr:even" ).css( "backgroundColor", "#dcfce7" );



// #other table rows unchanged — indices restart per matched set
Try It Yourself

How It Works

Scoping with an ID limits the matched set before indexing — indices always start at 0 within that set.

Example 4 — Modern Pattern: $(".row").even()

jQuery 3.5+ — replacement for the deprecated :even pseudo-class.

jQuery
$( ".row" ).even().css( "backgroundColor", "#bbf" );



// Same result as $( ".row:even" ) — preferred in new code
Try It Yourself

How It Works

Official jQuery 3.4 deprecation note points to .even() added in 3.5.0 as the direct replacement.

Example 5 — Performance: .filter(":even")

Official docs — pure CSS selector first, then jQuery index filter.

jQuery
$( ".card" ).filter( ":even" ).css( "borderColor", "#2563eb" );



// Browser optimizes $(".card"); jQuery filters to even indices
Try It Yourself

How It Works

Because :even is not standard CSS, embedding it in one selector string blocks querySelectorAll for the whole query. Splitting steps helps performance.

🚀 Common Use Cases

  • Table zebra stripingtr:even background alternation.
  • List styling — highlight every other li at even indices.
  • Grid layouts — style even-indexed cards in a flat matched set.
  • Complement with :odd — two-tone UI from one list query.
  • Legacy maintenance — read existing :even in older jQuery code.
  • Migration — replace with .even() or .filter(":even").

🧠 How jQuery Evaluates :even

1

Build matched set

Run the selector before :even — e.g. all tr or #sales tr.

Query
2

Assign indices

Number elements 0 through length − 1 in document order.

0-based
3

Filter even indices

Keep elements where index is 0, 2, 4, 6…

Filter
4

Return collection

Multiple elements in document order — ready for .css() or other chaining.

📝 Notes

  • Available since jQuery 1.0 — 0-based even indices (0, 2, 4…).
  • Deprecated in jQuery 3.4 — prefer .even() (3.5.0+) or .filter(":even").
  • First element always matches — index 0 is even (official docs emphasize this).
  • Pair with :odd for complementary sets — see also official :odd selector.
  • Not valid in native querySelectorAll — jQuery extension only.
  • Selected elements appear in document order within the filtered result.

Browser Support

The :even pseudo-class is a jQuery extension — not standard CSS — and works in jQuery 1.0+. It is deprecated in 3.4+; use .even() (3.5+) instead. The method works in all browsers that support jQuery.

jQuery 1.0+ · deprecated 3.4

jQuery :even Selector

Works in all jQuery versions. Modern code: $("tr").even() instead of $("tr:even").

100% jQuery only
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
:even Universal

Bottom line: Learn :even for legacy zebra striping; write new code with .even() after a pure CSS selector.

Conclusion

The :even selector matches elements at even zero-based indices in the matched set — the official tr:even demo stripes the first, third, and fifth rows. Remember that index 0 counts as even, and pair with :odd for alternating styles.

For jQuery 3.5+ projects, use .even() instead of the deprecated pseudo-class. When maintaining legacy code, understand the difference from CSS :nth-child(even).

💡 Best Practices

✅ Do

  • Use $("tr").even() in new jQuery 3.5+ code
  • Scope with an ID or class before indexing
  • Pair :even with :odd for full coverage
  • Remember index 0 is the first element
  • Use .filter(":even") after a CSS selector for performance

❌ Don’t

  • Assume :even skips the first row — it includes index 0
  • Add new :even selectors in modern codebases
  • Confuse with CSS :nth-child(even) blindly
  • Use bare $(":even") without a preceding selector
  • Expect native querySelectorAll("tr:even") to work

Key Takeaways

Knowledge Unlocked

Five things to remember about :even

Even 0-based indices in the matched set.

5
Core concepts
1st 02

First row

Index 0 counts

Tip
odd 03

:odd

Complement

Pair
.even 04

Modern

3.5+ method

New
demo 05

Official

tr:even

Demo

❓ Frequently Asked Questions

:even selects elements at even zero-based indices within the matched set — index 0, 2, 4, and so on. $("tr:even") matches the first, third, and fifth rows among all tr elements in scope. Available since jQuery 1.0.
jQuery uses 0-based indexing. Index 0 is even, so the first element in the matched set always matches :even. This is counter-intuitive if you think of "even" as the second row in human counting — official docs call this out explicitly.
:even matches indices 0, 2, 4… :odd matches indices 1, 3, 5… Together they partition the matched set. Official docs: see also :odd.
Yes — deprecated in jQuery 3.4. Official docs recommend removing :even from selectors and using the .even() method (available in jQuery 3.5.0+) on a collection: $("tr").even() instead of $("tr:even").
:even filters the jQuery matched set by 0-based position after your selector runs. CSS :nth-child(even) counts children within each parent (1-based). A scoped $("table tr:even") is not the same as tr:nth-child(even) in every layout.
Official docs: because :even is a jQuery extension, select with a pure CSS selector first, then filter — e.g. $(".row").filter(":even") or use .even() in jQuery 3.5+ so the browser can optimize the initial query.
Did you know?

Official jQuery docs warn that 0-based indexing makes :even counter-intuitive — it selects the first, third, and fifth elements, not the second, fourth, and sixth. If you want true “every second row starting from row 2,” use :odd instead, or CSS :nth-child(even) depending on your DOM structure.

Continue to :odd Selector

After :even, learn how :odd picks elements at indices 1, 3, 5… — the official tr:odd zebra demo.

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

6 people found this page helpful