jQuery .odd() Method

Beginner
5 min read
Updated: Oct 2026
5 examples
Live preview

What Is .odd()?

.odd() (since jQuery 3.5) reduces the matched set to elements at odd zero-based indexes — 1, 3, 5, …. It takes no arguments. Returns a new jQuery object; does not change the DOM.

Remember
$("li").odd();              // indexes 1, 3 → items 2 & 4
$("ul li").odd();           // official highlight demo
$("tr").odd();              // zebra table rows (2nd, 4th, …)

// Indexes:  0      1      2      3      4
// Items:    1st    2nd    3rd    4th    5th
// .odd() →         ✓             ✓
// .even() → ✓             ✓             ✓
NeedUse
Odd indexes (1, 3, 5…)$set.odd()
Even indexes (0, 2, 4…).even()
Older jQuery$("li:odd") or .filter(":odd")
One index.eq(1)
Custom keep/drop.filter() / .not()

How to Use .odd()

Select a set, call .odd(), then style or process the result.

  1. Confirm you are on jQuery 3.5+.
  2. Select the collection (e.g. $("ul li")).
  3. Call .odd() — no arguments.
  4. Remember: index 0 is even → the first item is not in .odd().
  5. Chain .append(), .addClass(), or .css() on the result.
PieceRequired?Role
Matched setYesCollection to reduce
ArgumentsNoneMethod takes no parameters
Index base—Zero-based position in the set
Return value—New jQuery set (0 or more)

Pseudocode

Pseudocode
call $(set).odd()

result = empty set
for each element in set with index i (starting at 0):
    if i % 2 === 1:          // odd index
        add element to result

return result as a new jQuery object

// 5 items → keeps indexes 1 and 3 (2nd & 4th)

Cheat Sheet

Keep odd/even methods side by side.

TopicDetail
Syntax.odd()
SincejQuery 3.5
KeepsIndexes 1, 3, 5, …
vs .even()Even indexes 0, 2, 4, …
vs :oddSame idea; method needs 3.5+
vs CSS :nth-child(odd)CSS is 1-based; .odd() is 0-based
DOM change?No — query only

Live Preview

From five list items, compare .odd(), .even(), and :odd.

  • list item 1
  • list item 2
  • list item 3
  • list item 4
  • list item 5

.odd() → items 2 and 4 (indexes 1 and 3). .even() → items 1, 3, and 5.

Result
Ready — choose a call and click Run.

jQuery Examples

Short, copy-ready snippets. Open DevTools, or use Try It Yourself for a live editor.

Example 1 — Official: $("li").odd()

Mark the 2nd and 4th list items (jQuery API demo).

jQuery
$("li").odd().append(" [odd]");
Try It Yourself

How It Works

  1. Select. Start with every li.
  2. Index. Positions are 0, 1, 2, 3, 4.
  3. Odd. Keep only indexes 1 and 3.
  4. Mark. The 2nd and 4th items get the suffix.

Example 2 — Official: $("ul li").odd()

Highlight odd-indexed items inside a list (jQuery API example).

jQuery
$("ul li").odd().append(" [highlight]");
Try It Yourself

How It Works

  1. Scope. $("ul li") limits the set to list items in the ul.
  2. Reduce. .odd() keeps odd indexes only.
  3. First out. The first li is index 0 (even) — skipped.
  4. Mark. Remaining odd-indexed items get the label.

Example 3 — .odd() vs .even()

Split one list into two non-overlapping groups.

jQuery
$("#demo li").odd().append(" [odd]");
$("#demo li").even().append(" [even]");
Try It Yourself

How It Works

  1. odd. Keeps indexes 1 and 3.
  2. even. Keeps indexes 0, 2, and 4.
  3. No overlap. Every item gets exactly one label.
  4. Use. Ideal for alternating styles / zebra rows.

Example 4 — .odd() vs :odd

Same zero-based idea — method (3.5+) vs selector.

jQuery
var a = $("li").odd().length;
var b = $("li:odd").length;

$("#out").text(".odd()=" + a + " · :odd=" + b);
Try It Yourself

How It Works

  1. Method. .odd() filters an existing set (needs 3.5+).
  2. Selector. :odd works in older jQuery builds.
  3. Same rule. Both use zero-based odd indexes.
  4. Prefer. Use .odd() when you already have a collection to chain.

Example 5 — Zebra Table Rows

Mark every other data row using odd indexes.

jQuery
$("tbody tr").odd().append(" ★");
Try It Yourself

How It Works

  1. Scope. Select only tbody tr so the header is ignored.
  2. Odd. Keep rows at indexes 1 and 3.
  3. Stripe. Those rows get a marker for zebra styling.
  4. Tip. Pair with .even() for the other stripe color.

Edge Cases & Pitfalls

Why “odd” can feel backwards at first.

zero

First item is index 0 (even)

.odd() skips the first element. The 2nd visual item is the first “odd” index.

version

Needs jQuery 3.5+

On older builds use $("li:odd") or .filter(":odd").

css

Not the same as CSS :nth-child(odd)

CSS child counting is 1-based. jQuery .odd() is 0-based on the matched set.

set

Indexes are in the jQuery set

Order depends on your selector. Reordering the DOM can change which nodes are “odd.”

Browser Support

.odd() was added in jQuery 3.5. It works in every browser that runs jQuery 3.5+. For older jQuery, use the :odd selector or .filter(":odd").

✓ jQuery 3.5+

jQuery .odd()

Supported in jQuery 3.5 and later (including 3.7.x). Zero-based odd indexes on the current matched set.

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() 3.5+

Bottom line: Safe on modern jQuery. Remember: counting starts at zero — the first item is even.

Performance Notes

ApproachCostBest for
.odd()Linear in set sizeAlternating items in a known collection
$("li:odd")SimilarOlder jQuery / one-shot select
Narrower start setFaster$("ul li") over $("*")

Prefer a tight selector first, then .odd(). The method only walks the current matched set.

Key Takeaways

  • Role: keep odd zero-based indexes — since jQuery 3.5.
  • Result: 2nd, 4th, 6th items — not the 1st.
  • Pair: use .even() for the other half.
  • Fallback: :odd on older jQuery builds.

One line: .odd() keeps indexes 1, 3, 5… — the 2nd, 4th, 6th elements in your set.

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.
Both use zero-based odd indexes on the matched set. .odd() is a method added in jQuery 3.5. $("li:odd") is the older selector form. Prefer .odd() on a current jQuery 3.5+ build for clearer chaining.
.odd() was added in jQuery 3.5. Older versions do not have this method — use $("li:odd") or .filter(":odd") instead.
No. It only returns a new jQuery object with the odd-indexed elements. Chain .css() or .addClass() if you want visual changes.

Next: .offsetParent() Method

Get the closest positioned ancestor for offset calculations.

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

10 people found this page helpful