jQuery .odd() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Traversing

Definition

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

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("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() → ✓             ✓             ✓
CallWhat it does
Matched setCollection to reduce
ArgumentsMethod takes no parameters
Index baseZero-based position in the set
Return valueNew jQuery set (0 or more)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Confirm you are on jQuery 3.5+.
Step 2Select the collection (e.g. $("ul li")).
Step 3Call .odd() — no arguments.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

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.

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.

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.

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: .filter() Method — Narrow Matched Elements

Get the closest positioned ancestor for offset calculations.

.filter() Method — Narrow Matched Elements tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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