jQuery :odd Selector

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Index filter

What You’ll Learn

The :odd selector matches elements at odd zero-based indices in the matched set — index 1, 3, 5, and so on. Available since jQuery 1.0; pair with :even; deprecated in jQuery 3.4 in favor of the .odd() method (3.5+).

01

Syntax

tr:odd

02

0-based

1, 3, 5…

03

Official

tr:odd

04

vs :even

0, 2, 4…

05

Second row

Index 1 = odd

06

.odd()

Modern API

Introduction

Alternating table rows, list highlights, and card grids often need every other element starting from the second item. jQuery’s :odd pseudo-class filters the matched set to elements at odd positions using zero-based indexing.

Official jQuery documentation notes a common surprise: because index 1 is odd, :odd selects the second element, fourth element, sixth element, and so on — not the first, third, fifth as everyday “odd row” numbering might suggest. Index selectors (:eq(), :lt(), :gt(), :even, :odd) always follow another selector that builds the matched set.

Understanding the :odd Selector

Think of :odd as keeping every other slot starting at index 1:

  • tr:eq(1), tr:eq(3), tr:eq(5) → same indices as tr:odd.
  • Four rows indexed 0–3 → :odd matches rows 1 and 3 (second and fourth).
  • :even matches the complement — indices 0 and 2 (first and third).
  • Selected elements stay in document order within the filtered set.
💡
Beginner Tip

For new code on jQuery 3.5+, prefer $("tr").odd() over $("tr:odd"). For performance with older patterns, use $("tr").filter(":odd") after a pure CSS selector.

📝 Syntax

Official jQuery API form (since 1.0):

jQuery
jQuery( ":odd" )

// typical usage — chain after a selector:
$( "tr:odd" )
$( "li:odd" )
$( "#salesTable tr:odd" )

// modern replacement (jQuery 3.5+):
$( "tr" ).odd()

// performance pattern:
$( "tr" ).filter( ":odd" )

Parameters

  • No arguments — keeps elements at odd 0-based indices in the matched set.

Return value

  • A jQuery object containing every odd-indexed element (may be multiple).
  • Empty collection when the matched set has fewer than two elements (index 1 required).

Official jQuery API example

jQuery
// Finds odd table rows — index 1, 3, 5…
$( "tr:odd" ).css( "background-color", "#bbbbff" );

⚡ Quick Reference

Index:even:odd
0 (first)MatchesNo match
1 (second)No matchMatches
2 (third)MatchesNo match
3 (fourth)No matchMatches
jQuery 3.5+.even().odd()

📋 :odd vs :even and CSS :nth-child

Index filters on the matched set vs child-position CSS.

:odd
tr:odd

Indices 1, 3, 5…

:even
tr:even

Indices 0, 2, 4…

.odd()
$("tr").odd()

Recommended 3.5+

nth-child
tr:nth-child(odd)

CSS per parent

Examples Gallery

Example 1 follows the official jQuery tr:odd demo. Examples 2–5 compare with :even, scope to one table, use the modern .odd() method, and apply the official .filter(":odd") performance pattern.

📚 Official jQuery Demo

Zebra stripe odd-indexed table rows — second, fourth, and so on.

Example 1 — Official Demo: tr:odd

Official jQuery demo — light blue background on rows at index 1, 3, 5…

jQuery
$( "tr:odd" ).css( "background-color", "#bbbbff" );

// Row #1 and #3 highlighted — Row #0 and #2 unchanged
Try It Yourself

How It Works

All tr elements are numbered 0-based in document order; :odd keeps indices where index % 2 === 1.

Example 2 — :odd vs :even

Apply different styles to complementary index sets on the same list.

jQuery
$( "#list li:odd" ).css( "backgroundColor", "#bbbbff" );
$( "#list li:even" ).css( "color", "#059669" );

// :odd → 2 items (1, 3) · :even → 3 items (0, 2, 4)
Try It Yourself

How It Works

:odd and :even partition the matched set — every element matches exactly one of them.

📈 Practical Patterns

Scoping, modern API, and performance filtering.

Example 3 — Scoped Striping: $("#sales tr:odd")

Highlight odd-indexed rows in one table without affecting others on the page.

jQuery
$( "#sales tr:odd" ).css( "backgroundColor", "#fef3c7" );

// #other table rows unchanged — indices restart per matched set
Try It Yourself

How It Works

Scoping with an ID limits the matched set before indexing — indices always start at 0 within that set.

Example 4 — Modern Pattern: $(".row").odd()

jQuery 3.5+ — replacement for the deprecated :odd pseudo-class.

jQuery
$( ".row" ).odd().css( "backgroundColor", "#bbbbff" );

// Same result as $( ".row:odd" ) — preferred in new code
Try It Yourself

How It Works

Official jQuery 3.4 deprecation note points to .odd() added in 3.5.0 as the direct replacement.

Example 5 — Performance: .filter(":odd")

Official docs — pure CSS selector first, then jQuery index filter.

jQuery
$( ".card" ).filter( ":odd" ).css( "borderColor", "#7c3aed" );

// Browser optimizes $(".card"); jQuery filters to odd indices
Try It Yourself

How It Works

Because :odd is not standard CSS, embedding it in one selector string blocks querySelectorAll for the whole query. Splitting steps helps performance.

🚀 Common Use Cases

  • Table zebra stripingtr:odd on rows starting from the second (index 1).
  • List styling — highlight every other li at odd indices.
  • Grid layouts — style odd-indexed cards in a flat matched set.
  • Complement with :even — two-tone UI from one list query.
  • Legacy maintenance — read existing :odd in older jQuery code.
  • Migration — replace with .odd() or .filter(":odd").

🧠 How jQuery Evaluates :odd

1

Build matched set

Run the selector before :odd — e.g. all tr or #sales tr.

Query
2

Assign indices

Number elements 0 through length − 1 in document order.

0-based
3

Filter odd indices

Keep elements where index is 1, 3, 5, 7…

Filter
4

Return collection

Multiple elements in document order — ready for .css() or other chaining.

📝 Notes

  • Available since jQuery 1.0 — 0-based odd indices (1, 3, 5…).
  • Deprecated in jQuery 3.4 — prefer .odd() (3.5.0+) or .filter(":odd").
  • Second element always matches when present — index 1 is odd (official docs emphasize this).
  • Pair with :even for complementary sets — see also official :even selector.
  • Not valid in native querySelectorAll — jQuery extension only.
  • Selected elements appear in document order within the filtered result.

Browser Support

The :odd pseudo-class is a jQuery extension — not standard CSS — and works in jQuery 1.0+. It is deprecated in 3.4+; use .odd() (3.5+) instead. The method works in all browsers that support jQuery.

jQuery 1.0+ · deprecated 3.4

jQuery :odd Selector

Works in all jQuery versions. Modern code: $("tr").odd() instead of $("tr:odd").

100% jQuery only
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: Learn :odd for legacy zebra striping; write new code with .odd() after a pure CSS selector.

Conclusion

The :odd selector matches elements at odd zero-based indices in the matched set — the official tr:odd demo stripes the second, fourth, and sixth rows. Remember that index 1 counts as odd, and pair with :even for alternating styles.

For jQuery 3.5+ projects, use .odd() instead of the deprecated pseudo-class. When maintaining legacy code, understand the difference from CSS :nth-child(odd).

💡 Best Practices

✅ Do

  • Use $("tr").odd() in new jQuery 3.5+ code
  • Scope with an ID or class before indexing
  • Pair :odd with :even for full coverage
  • Remember index 1 is the second element
  • Use .filter(":odd") after a CSS selector for performance

❌ Don’t

  • Assume :odd selects the first row — it starts at index 1
  • Add new :odd selectors in modern codebases
  • Confuse with CSS :nth-child(odd) blindly
  • Use bare $(":odd") without a preceding selector
  • Expect native querySelectorAll("tr:odd") to work

Key Takeaways

Knowledge Unlocked

Five things to remember about :odd

Odd 0-based indices in the matched set.

5
Core concepts
2nd 02

Second row

Index 1 counts

Tip
even 03

:even

Complement

Pair
.odd 04

Modern

3.5+ method

New
demo 05

Official

tr:odd

Demo

❓ Frequently Asked Questions

:odd selects elements at odd zero-based indices within the matched set — index 1, 3, 5, and so on. $("tr:odd") matches the second, fourth, and sixth rows among all tr elements in scope. Available since jQuery 1.0.
jQuery uses 0-based indexing. Index 1 is odd, so the second element in the matched set always matches :odd. Official jQuery docs call this counter-intuitive if you expect :odd to mean the first row — use :even for index 0, 2, 4… instead.
:odd matches indices 1, 3, 5… :even matches indices 0, 2, 4… Together they partition the matched set with no overlap. Official docs: see also :even.
Yes — deprecated in jQuery 3.4. Official docs recommend removing :odd from selectors and using the .odd() method (available in jQuery 3.5.0+) on a collection: $("tr").odd() instead of $("tr:odd").
:odd filters the jQuery matched set by 0-based position after your selector runs. CSS :nth-child(odd) counts children within each parent (1-based). A scoped $("table tr:odd") is not the same as tr:nth-child(odd) in every layout.
Official docs: because :odd is a jQuery extension, select with a pure CSS selector first, then filter — e.g. $(".row").filter(":odd") or use .odd() in jQuery 3.5+ so the browser can optimize the initial query.
Did you know?

Official jQuery docs warn that 0-based indexing makes :odd counter-intuitive — it selects the second, fourth, and sixth elements, not the first, third, and fifth. If you want true “every first row in a pair,” use :even instead, or CSS :nth-child(odd) depending on your DOM structure.

Continue to :first Selector

After :odd, learn how :first picks the leading element in a matched set — equivalent to :eq(0).

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

6 people found this page helpful