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
Fundamentals
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.
Concept
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.
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" );
Cheat Sheet
⚡ Quick Reference
Index
:even
:odd
0 (first)
Matches
No match
1 (second)
No match
Matches
2 (third)
Matches
No match
3 (fourth)
No match
Matches
jQuery 3.5+
.even()
.odd()
Compare
📋 :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
Hands-On
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
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.
Important
📝 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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
:evenUniversal
Bottom line: Learn :even for legacy zebra striping; write new code with .even() after a pure CSS selector.
Wrap Up
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).
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :even
Even 0-based indices in the matched set.
5
Core concepts
001
:even
0, 2, 4…
API
1st02
First row
Index 0 counts
Tip
odd03
:odd
Complement
Pair
.even04
Modern
3.5+ method
New
demo05
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.