jQuery .odd() Method

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Odd indexes (0-based)

What You’ll Learn

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+

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.

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.

📝 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

⚡ Quick Reference

GoalCode
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)

📋 .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)

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.

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

How It Works

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.

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

How It Works

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

📈 Practical Patterns

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

Example 3 — .odd() and .even() 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", "#fff3cd" );
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 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.

jQuery
$( "#data-table tbody tr" )

  .odd()

  .addClass( "row-odd" );
Try It Yourself

How It Works

Index is relative to the tbody tr collection. Pair with .even() on the same set or style only one group — both produce readable zebra tables.

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

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

jQuery
$( "li" )

  .filter( ".active" )

  .odd()

  .css( "font-weight", "bold" );



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

How It Works

After .filter(".active") shrinks the set, .odd() counts indexes within that subset — not among all li elements on the page.

🚀 Common Use Cases

  • Zebra table rows$("tbody tr").odd().addClass("alt").
  • 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

Return & chain

New jQuery object — push stack for .end().

📝 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.

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 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
.odd() Universal

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

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().

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about .odd()

Indexes 1, 3, 5 — zero-based.

5
Core concepts
0,2 02

.even()

Pair

Compare
0 03

Zero

Start here

Index
:odd 04

:odd

Selector

Related
3.5 05

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.

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