jQuery :odd Selector

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

What Is :odd?

:odd selects elements at odd zero-based indexes in the matched set — positions 1, 3, 5… (the 2nd, 4th, 6th elements). Available since jQuery 1.0. See also :even.

Deprecated (jQuery 3.4)

Remove :odd from selectors. Prefer .odd() (jQuery 3.5+) or .filter(":odd") after a CSS query.

Remember
$(":odd")
$("tr:odd")              → indexes 1, 3, 5… in the tr set
$("tr").odd()            → same idea (jQuery 3.5+)

indexes:  0   1   2   3
          even odd even odd

:odd  → 2nd, 4th, 6th… elements (counter-intuitive!)
:even → 1st, 3rd, 5th… elements
UsePrefer
Modern jQuery (3.5+)$("tr").odd()
Legacy / learning$("tr:odd") or $("tr").filter(":odd")
Parent-aware striping$("tr:nth-child(odd)")

How to Use :odd

Match a set first, then keep only odd indexes in that flat list.

  1. Select the elements you care about (tr, li, and so on).
  2. Filter with :odd, .filter(":odd"), or .odd().
  3. Remember: index 1 is the second element.
  4. For new code on jQuery 3.5+, use .odd() instead of :odd.
PieceRequired?Role
Base selectorUsuallyBuilds the matched set to filter
:odd / .odd()YesKeeps odd 0-based indexes
Document order—Results follow appearance in the DOM

Pseudocode

Pseudocode
set = find(baseSelector)   // document order
result = empty

for i from 0 to set.length - 1:
    if i is odd:           // 1, 3, 5…
        keep set[i]

return jQuery(result)

Cheat Sheet

Keep these facts handy while filtering odd positions.

TopicDetail
Syntax$(":odd") / $("sel").odd()
Indexes0-based: keeps 1, 3, 5…
First match2nd element in the set (index 1)
vs :evenOdd vs even indexes; no overlap
vs :nth-child(odd)Flat set vs parent child slots
StatusDeprecated in 3.4; use .odd() (3.5+)
SincejQuery 1.0 (extension, not CSS)

Live Preview

Compare :odd, :even, and parent-aware :nth-child(odd) on a small table.

Official-style rows labeled by zero-based index.

Result
$("tr:odd")
matched: 2
text: Row with Index #1, Row with Index #3

/* 0-based odd indexes → 2nd, 4th… */

jQuery Examples

Short, copy-ready snippets. Open a browser console with jQuery loaded, or use Try It Yourself for a live editor.

Example 1 — Official Demo: tr:odd

Find odd table rows — second, fourth, and so on (jQuery API example).

jQuery
var names = $("tr:odd").map(function () {
  return this.textContent.trim();
}).get().join(", ");

console.log($("tr:odd").length);
console.log(names);
Try It Yourself

How It Works

  1. Match all rows. $("tr") builds a flat set in document order.
  2. Keep odd indexes. Positions 1 and 3 remain.
  3. Skip even indexes. Rows #0 and #2 are excluded.
  4. Classic zebra use. Official demo styles those rows with a background color.

Example 2 — Why the Second Element Matches

Print each index so the 0-based rule is obvious.

jQuery
$("li").each(function (i) {
  console.log(i, this.textContent.trim(), i % 2 === 1 ? "ODD" : "even");
});

console.log("odd texts:", $("li:odd").map(function () {
  return this.textContent.trim();
}).get().join(", "));
Try It Yourself

How It Works

  1. List indexes. jQuery’s .each() callback receives the 0-based index.
  2. Test oddness. i % 2 === 1 marks what :odd keeps.
  3. Second item first. Index 1 is the first odd slot.
  4. Mental model. Think “every other item starting at the second.”

Example 3 — :odd vs :even

The two selectors split a set cleanly with no overlap.

jQuery
console.log("odd:", $("tr:odd").map(function () {
  return this.textContent.trim();
}).get().join(", "));

console.log("even:", $("tr:even").map(function () {
  return this.textContent.trim();
}).get().join(", "));

console.log("total:", $("tr").length);
Try It Yourself

How It Works

  1. Odd half. Indexes 1 and 3.
  2. Even half. Indexes 0 and 2.
  3. No overlap. Every matched element lands in exactly one group.
  4. Pair them. Zebra UIs often style both halves differently.

Example 4 — :odd vs :nth-child(odd)

Flat set filtering is not the same as parent-aware CSS odd children.

jQuery
console.log(":odd →", $("tr:odd").map(function () {
  return this.textContent.trim();
}).get().join(", "));

console.log("nth-child(odd) →", $("tr:nth-child(odd)").map(function () {
  return this.textContent.trim();
}).get().join(", "));
Try It Yourself

How It Works

  1. jQuery :odd. Uses 0-based set indexes → 2nd and 4th rows.
  2. CSS :nth-child(odd). Uses 1-based child positions → 1st and 3rd rows.
  3. Same word, different math. “Odd” alone is ambiguous — know which system you mean.
  4. Parent-aware striping. Prefer :nth-child(odd) when each table body restarts numbering.

Example 5 — Prefer .odd() (jQuery 3.5+)

Same filter as :odd, without the deprecated pseudo-class in the selector string.

jQuery
var $byPseudo = $("tr:odd");
var $byMethod = $("tr").odd();   // jQuery 3.5+

console.log($byPseudo.length === $byMethod.length);
console.log($byMethod.map(function () {
  return this.textContent.trim();
}).get().join(", "));
Try It Yourself

How It Works

  1. Select first. $("tr") uses a fast CSS query.
  2. Filter with .odd(). Keeps odd indexes on that collection.
  3. Same result. Length and nodes match $("tr:odd").
  4. Future-proof. Official migration path after the 3.4 deprecation — see .odd().

Edge Cases & Pitfalls

Check these before relying on :odd in real projects.

deprecated

Deprecated since jQuery 3.4

Official docs: remove :odd from selectors; use .odd() (3.5+) or .filter(":odd").

index

Counter-intuitive first match

:odd starts at the second element (index 1). Want the first row? That is :even.

scope

Flat set, not per parent

$("tr:odd") numbers every matched row in the document. Multiple tables share one index sequence unless you scope first.

perf

Not a CSS selector

Cannot use querySelectorAll alone. Select with CSS, then filter — official performance note.

Browser Support

:odd is a jQuery extension (not CSS), available since 1.0. It works wherever jQuery runs, but is deprecated in 3.4. Prefer .odd() from jQuery 3.5+.

✓ jQuery 1.0+ · Deprecated 3.4

jQuery :odd

Works in all browsers with jQuery. Not available in native querySelectorAll. Migrate to .odd() for modern code.

100% jQuery environments
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 jQuery only

Bottom line: Supported for compatibility, but plan to replace :odd with .odd() or .filter(":odd") in new work.

Performance Notes

ApproachCostBest for
$("tr").odd()CSS query + filterModern jQuery (recommended)
$("tr").filter(":odd")CSS query + filterOfficial perf pattern
$("tr:odd")Sizzle path (no QSA)Legacy only

Official docs: because :odd is not CSS, select with a pure CSS selector first, then filter. That lets the browser optimize the initial query.

Key Takeaways

  • Role: keep odd 0-based indexes in a flat matched set.
  • Gotcha: first match is the second element.
  • Deprecated: prefer .odd() in jQuery 3.5+.
  • Not CSS odd: different from :nth-child(odd).

One line: :odd means “every other match starting at the second” — and modern code should use .odd().

Frequently Asked Questions

:odd selects elements at odd zero-based indexes in the matched set — 1, 3, 5, and so on. $("tr:odd") matches the second, fourth, and sixth rows among matched tr elements. Available since jQuery 1.0.
Indexing is 0-based. Index 1 is odd, so the second element matches. Official docs call this counter-intuitive if you expect the first row — use :even for indexes 0, 2, 4…
:odd matches 1, 3, 5… :even matches 0, 2, 4… Together they partition the matched set with no overlap.
Yes — deprecated in jQuery 3.4. Prefer $("tr").odd() (jQuery 3.5+) or $("tr").filter(":odd") instead of $("tr:odd").
:odd filters the flat jQuery matched set (0-based). CSS :nth-child(odd) counts children within each parent (1-based). They can select different nodes.
Official docs: :odd is a jQuery extension, so it cannot use querySelectorAll alone. Select with a CSS selector first, then .filter(":odd") or .odd().

Next: :first Selector

Select the first element in a matched set with the :first selector.

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

11 people found this page helpful