jQuery .even() Method

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Even indexes

What You’ll Learn

The .even() traversing method keeps elements at even zero-based indexes — 0, 2, 4 — from the current jQuery collection. This tutorial covers the official list highlight demos, zebra-striping patterns, comparison with .odd() and the :even selector, and clarifies the difference from CSS :nth-child(even).

01

Syntax

.even()

02

Indexes

0, 2, 4…

03

Zero-based

From zero

04

vs .odd()

1, 3, 5…

05

Zebra rows

Striping

06

Since 3.5

jQuery API

Introduction

Alternating styles — zebra-striped table rows, every other list item highlighted — are common UI patterns. Instead of looping with an index check, jQuery provides .even() to select every element at an even position in the current collection.

Added in jQuery 3.5, .even() takes no arguments and returns a new jQuery object containing elements at indexes 0, 2, 4, and so on. Counting is zero-based — the first element is index 0, which counts as “even.”

Understanding the .even() Method

Given a jQuery object with one or more matched elements, .even() filters the collection to those whose zero-based index is even (index % 2 === 0). The index is position within the jQuery object — in document order for a simple $("li") query, but relative to whatever set you have after prior filtering.

Pair .even() with .odd() to style alternating groups. For legacy jQuery before 3.5, use .filter(":even") instead — it follows the same zero-based index rule.

💡
Beginner Tip

In a five-item list, .even() selects items 1, 3, and 5 (human counting) because their indexes are 0, 2, and 4. Item 2 is index 1 — odd, not even.

📝 Syntax

General form of .even:

jQuery
.even()

Parameters

  • None — .even() does not accept any arguments.

Return value

  • A new jQuery object containing elements at even zero-based indexes (0, 2, 4…) from the original set.

Official jQuery API list example

jQuery
$( "li" ).even().css( "background-color", "red" );
// Indexes 0, 2, 4 → list items 1, 3, 5

⚡ Quick Reference

GoalCode
Even-indexed elements$("li").even()
Odd-indexed elements$("li").odd()
Style even rows red$("tr").even().css("background", "#fee")
Legacy jQuery (< 3.5)$("li").filter(":even")
Manual index filter$("li").filter(function(i){ return i % 2 === 0; })
Selector at query time$("li:even")

📋 .even() vs .odd() vs :even vs CSS

Four ways to target alternating elements — know which index system each uses.

.even()
0, 2, 4

Method; zero-based collection index (jQuery 3.5+)

.odd()
1, 3, 5

Complement — odd indexes in same set

:even
selector

Same zero-based rule; used in selector string

:nth-child
CSS 1-based

DOM sibling position; different from .even()

Item (human #)Zero-based index.even().odd()
1st0
2nd1
3rd2
4th3
5th4

Examples Gallery

Examples 1–2 follow the official jQuery API documentation. Use DevTools or the Try-it links to run each snippet in the browser.

📚 Getting Started

Official jQuery demos for even-index selection.

Example 1 — Official Demo: Red Background on Even Items

Style list items at indexes 0, 2, and 4 — the 1st, 3rd, and 5th items.

jQuery
$( "li" ).even().css( "background-color", "red" );
Try It Yourself

How It Works

Indexes 0, 2, 4 are even in zero-based counting. The jQuery API stresses: counting starts from zero, not one.

Example 2 — Official Demo: Add Highlight Class to Even li

Apply class highlight to even items inside ul li — official demo pattern.

jQuery
$( "ul li" ).even().addClass( "highlight" );
Try It Yourself

How It Works

After $("ul li") builds the collection, .even() narrows it before .addClass(). Works on any matched set, not just top-level lists.

📈 Practical Patterns

Pair with .odd(), zebra tables, and filtered collections.

Example 3 — .even() and .odd() Together

Apply different background colors to alternating groups in the same list.

jQuery
var $items = $( "#striped li" );

$items.even().css( "background-color", "#e8f4fc" );
$items.odd().css( "background-color", "#fff" );
Try It Yourself

How It Works

Store the collection once, then call .even() and .odd() separately. Every element lands in exactly one group — indexes partition the set.

Example 4 — Zebra-Striped Table Rows

Classic data-table pattern: highlight even tbody tr rows for readability.

jQuery
$( "#data-table tbody tr" )
  .even()
  .addClass( "row-even" );
Try It Yourself

How It Works

Index is relative to the tbody tr collection — header rows in thead are excluded because they are not in the matched set.

Example 5 — .even() After .filter()

Indexes are collection-relative — even applies to positions in the filtered result, not the original DOM list.

jQuery
$( "li" )
  .filter( ".active" )
  .even()
  .css( "font-weight", "bold" );

// Only .active items; then even indexes among those
Try It Yourself

How It Works

After .filter(".active"), the collection may be smaller. .even() indexes into that new set — not the original full li list.

🚀 Common Use Cases

  • Zebra table rows — shade every other row for readability.
  • Alternating list styles — different backgrounds on even-index items.
  • Carousel indicators — style even-positioned dots or thumbnails.
  • Grid layouts — highlight even cells in a flattened node list.
  • Split A/B styling — pair .even() and .odd() for two visual groups.
  • Post-filter striping — stripe only visible items after a search filter.

🧠 How .even() Filters by Index

1

Start with collection

jQuery object holds N elements in order.

Input
2

Check each index

Keep element when index % 2 === 0.

0, 2, 4
3

Build new set

Return jQuery object with matching elements only.

Subset
4

Chain styling

Apply .css(), .addClass(), or events on even items.

📝 Notes

  • Added in jQuery 3.5 — requires jQuery 3.5+; use .filter(":even") on older versions.
  • Zero-based indexing — index 0 is the first element and counts as even.
  • Index is relative to the current jQuery collection, not global DOM order after filtering.
  • Does not modify the DOM — only narrows which elements the jQuery object refers to.
  • Complements .odd() — together they cover all indexes without overlap.
  • Not equivalent to CSS :nth-child(even), which uses sibling-based 1-based counting.

Browser Support

.even() requires jQuery 3.5+. It is pure collection filtering with no browser-specific behavior beyond jQuery itself.

jQuery 3.5+

jQuery .even()

Supported in jQuery 3.5, 3.6, and 3.7 across all modern browsers. Not available in jQuery 1.x/2.x — use .filter(':even') instead.

100% With jQuery 3.5+
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() Modern jQuery

Bottom line: Use jQuery 3.5 or later. Pair with .odd() for full alternating striping patterns.

Conclusion

The jQuery .even() method selects elements at even zero-based indexes from the current collection — 0, 2, 4, and so on. It is the clean, readable way to stripe lists and tables without manual index loops.

Remember the official list lesson: in five items, .even() highlights the 1st, 3rd, and 5th because their indexes are 0, 2, and 4. Use .odd() for the complement, and verify you are on jQuery 3.5+.

💡 Best Practices

✅ Do

  • Remember zero-based counting — first item is index 0 (even)
  • Pair .even() with .odd() for full striping
  • Use on tbody tr for table zebra rows
  • Cache the collection when calling both .even() and .odd()
  • Use .filter(":even") only when stuck on jQuery < 3.5

❌ Don’t

  • Assume human 2nd/4th items — those are odd indexes (1, 3)
  • Confuse .even() with CSS :nth-child(even)
  • Expect .even() on jQuery 3.4 or earlier without a polyfill
  • Forget that filtering changes which indexes count as “even”
  • Call .even() twice expecting a smaller set — second pass re-indexes from zero

Key Takeaways

Knowledge Unlocked

Five things to remember about .even()

Indexes 0, 2, 4 from the current set.

5
Core concepts
0 02

Zero-based

From 0

Index
03

Zebra

Striping

Pattern
1,3 04

.odd()

Complement

Pair
3.5 05

Since 3.5

Modern

Version

❓ Frequently Asked Questions

.even() reduces the current jQuery collection to elements at even zero-based indexes — 0, 2, 4, and so on. In a five-item list, that means the 1st, 3rd, and 5th elements (indices 0, 2, 4).
Yes. Counting starts from zero, as the jQuery API docs emphasize. Index 0 is the first element, index 2 is the third, index 4 is the fifth. This is index position in the jQuery object, not CSS :nth-child numbering.
.even() keeps indexes 0, 2, 4… .odd() keeps indexes 1, 3, 5… Together they split a collection into two alternating groups — useful for zebra-striped rows or alternating list styles.
Both target even indexes, but :even is used inside a selector string at query time — $('tr:even'). .even() is a method on an existing jQuery collection — $('tr').even(). Prefer .even() when filtering an already-matched set after .filter() or .find().
No. CSS :nth-child(even) counts DOM child position among siblings (1-based). jQuery .even() counts position in the current jQuery collection (0-based). They often overlap on simple lists but can differ after filtering or complex selectors.
.even() was added in jQuery 3.5. Use jQuery 3.5 or later. In older jQuery versions, use .filter(':even') or .filter(function(i){ return i % 2 === 0; }) instead.
Did you know?

jQuery added .even() and .odd() in version 3.5 as clearer alternatives to the :even and :odd selector pseudos. The naming mirrors native JavaScript array methods, but the index rule matches the long-standing jQuery pseudo-selectors — zero-based, which surprises developers expecting “even” to mean 2nd and 4th items in everyday counting.

Back to jQuery Traversing

Explore more DOM traversal methods as the collection grows.

Traversing hub →

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