The .odd() traversing method keeps elements at odd zero-based indexes — 1, 3, 5 — from the current jQuery collection. This tutorial covers the official list highlight demos, zebra-striping patterns, comparison with .even() and the :odd selector, and clarifies the difference from CSS :nth-child(odd).
01
Indexes 1,3,5
Zero-based
02
No args
Simple API
03
vs .even()
Alternating
04
vs :odd
Method form
05
Zebra rows
Tables/lists
06
Since 3.5
jQuery 3.5+
Fundamentals
Introduction
Alternating styles — every other table row, every second list item, striped galleries — are everywhere in UI design. The .odd() method selects elements at odd positions in the current jQuery collection, starting count from zero.
Added in jQuery 3.5 alongside .even(), .odd() takes no arguments. It is the complement of .even(): together they partition any matched set into two non-overlapping groups. Index position is relative to the jQuery object — not the original DOM query — which matters after .filter() or other narrowing steps.
Concept
Understanding the .odd() Method
Given a jQuery object representing a set of DOM elements, .odd() constructs a new jQuery object containing only elements whose zero-based index in that set is odd — 1, 3, 5, 7, and so on. Element at index 0 is excluded; index 1 is included.
The jQuery API is explicit: counting starts from zero. In a five-item list, .odd() selects the 2nd and 4th items (indices 1 and 3), not the 1st, 3rd, and 5th. That surprises beginners who expect “odd” to mean 1st, 3rd, 5th in everyday one-based counting — that group is .even() in jQuery’s zero-based system.
💡
Beginner Tip
$("li").odd() → items 2 and 4 (indexes 1, 3). $("li").even() → items 1, 3, 5 (indexes 0, 2, 4). Together they cover every element exactly once.
Foundation
📝 Syntax
General form of .odd:
jQuery
.odd()
Parameters
None — .odd() does not accept any arguments.
Return value
A new jQuery object containing elements at odd zero-based indexes in the current set.
Official jQuery API list example
jQuery
$( "li" ).odd().css( "background-color", "red" );
// Red on items 2 and 4 — indexes 1 and 3 in zero-based counting
Cheat Sheet
⚡ Quick Reference
Goal
Code
Odd-indexed list items
$("li").odd()
Highlight odd rows in tbody
$("tbody tr").odd().addClass("alt")
Even-indexed complement
$("li").even()
At query time with pseudo
$("tr:odd")
Legacy jQuery (< 3.5)
$("li").filter(":odd")
Single element by index
$("li").eq(1)
Compare
📋 .odd() vs .even() vs :odd vs CSS
Four ways to target alternating elements — method, complement, pseudo, and CSS.
.odd()
1, 3, 5…
Odd indexes in current jQuery set
.even()
0, 2, 4…
Even indexes — complement of .odd()
:odd
selector
Pseudo at query time — $('tr:odd')
:nth-child
CSS 1-based
DOM sibling position — not jQuery index
5-item list
.odd()
.even()
Item 1 (index 0)
—
✓
Item 2 (index 1)
✓
—
Item 3 (index 2)
—
✓
Item 4 (index 3)
✓
—
Item 5 (index 4)
—
✓
Hands-On
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 odd-index selection.
Example 1 — Official Demo: Red Background on Odd Items
Style list items at indexes 1 and 3 — the 2nd and 4th items.
Indexes 1 and 3 are odd in zero-based counting. The jQuery API stresses: counting starts from zero — the 2nd and 4th visual items, not the 1st, 3rd, and 5th.
Example 2 — Official Demo: Add Highlight Class to Odd li
Apply class highlight to odd items inside ul li — official demo pattern.
Indexes 0,2,4 → light blue
Indexes 1,3 → light yellow
Full zebra striping effect
How It Works
Store the collection once, then call .even() and .odd() separately. Every element lands in exactly one group — indexes partition the set with no overlap.
Example 4 — Zebra-Striped Table Rows (Odd Rows)
Highlight odd tbody tr rows — alternate stripe when even rows use the default background.
Alternating list styles — pair .even() and .odd() for two-tone lists.
Gallery thumbnails — style every other tile in a matched grid collection.
Split A/B styling — odd group gets one treatment, even group another.
After narrowing — .filter(".visible").odd() for alternating visible items only.
Legacy fallback — .filter(":odd") when jQuery < 3.5.
🧠 How .odd() Selects by Index
1
Start with matched set
jQuery object holds ordered DOM elements.
Input
2
Check each index
Zero-based: keep when index % 2 === 1.
Index
3
Build subset
Elements at indexes 1, 3, 5… form the result.
Filter
4
1,3,5
Return & chain
New jQuery object — push stack for .end().
Important
📝 Notes
Added in jQuery 3.5 — requires jQuery 3.5 or later.
No arguments — unlike .eq() or .filter().
Zero-based indexing — index 1 is the second element, not the first.
Index is relative to the current jQuery collection, not the full DOM query.
Complements .even() — together they cover all indexes without overlap.
Not the same as CSS :nth-child(odd) — different counting rules.
Compatibility
Browser Support
.odd() requires jQuery 3.5+. It uses index filtering with no browser-specific behavior beyond jQuery itself.
✓ jQuery 3.5+
jQuery .odd()
Supported in jQuery 3.5, 3.6, 3.7 across all modern browsers. For jQuery 1.x–3.4, use .filter(':odd') instead. Native CSS :nth-child(odd) handles styling without JavaScript when pure CSS suffices.
100%With jQuery 3.5+
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
.odd()Universal
Bottom line: Use jQuery 3.5 or later. Pair with .even() for full alternating striping patterns.
Wrap Up
Conclusion
The jQuery .odd() method reduces the current collection to elements at odd zero-based indexes — 1, 3, 5, and so on. It is the natural complement to .even() for alternating styles and zebra-striped layouts.
Remember the official list lesson: in five items, .odd() styles the 2nd and 4th (indexes 1 and 3). Use .even() for the other group, and verify you are on jQuery 3.5+ before calling .odd().
Remember zero-based counting — odd means indexes 1, 3, 5…
Pair .odd() with .even() for full striping
Apply after .filter() when indexes should be collection-relative
Cache the collection when calling both .even() and .odd()
Use CSS :nth-child when styling alone needs no jQuery chain
❌ Don’t
Assume odd means 1st, 3rd, 5th in everyday counting — that is .even()
Use .odd() on jQuery versions before 3.5 without a fallback
Confuse jQuery index with CSS :nth-child(odd)
Expect .odd() to accept a selector — use .filter() first
Forget that filtered collections renumber indexes from zero
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .odd()
Indexes 1, 3, 5 — zero-based.
5
Core concepts
1,301
.odd()
Odd idx
API
0,202
.even()
Pair
Compare
003
Zero
Start here
Index
:odd04
:odd
Selector
Related
3.505
Version
3.5+ req
Note
❓ Frequently Asked Questions
.odd() reduces the current jQuery collection to elements at odd zero-based indexes — 1, 3, 5, and so on. In a five-item list, that means the 2nd and 4th elements (indices 1 and 3).
Yes. Counting starts from zero, as the jQuery API docs emphasize. Index 1 is the second element, index 3 is the fourth. This is position in the jQuery object, not CSS :nth-child numbering.
.odd() keeps indexes 1, 3, 5… .even() keeps indexes 0, 2, 4… Together they split a collection into two alternating groups with no overlap — ideal for zebra-striped rows or alternating list styles.
Both target odd indexes, but :odd is used inside a selector string at query time — $('tr:odd'). .odd() is a method on an existing jQuery collection — $('tr').odd(). Prefer .odd() when filtering an already-matched set after .filter() or .find().
No. CSS :nth-child(odd) counts DOM child position among siblings (1-based). jQuery .odd() counts position in the current jQuery collection (0-based). They often overlap on simple lists but can differ after filtering or complex selectors.
.odd() was added in jQuery 3.5 alongside .even(). Use jQuery 3.5 or later. In older jQuery versions, use .filter(':odd') or .filter(function(i){ return i % 2 === 1; }) 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 means .odd() highlights the 2nd and 4th items, not the 1st and 3rd as everyday “odd-numbered” counting would suggest.