jQuery :odd Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

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

Syntax

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

jQuery
$(":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
CallWhat it does
Base selectorBuilds the matched set to filter
:odd / .odd()Keeps odd 0-based indexes
Document orderResults follow appearance in the DOM

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

Parameters

ParameterDescription
Step 1Select the elements you care about (tr, li, and so on).
Step 2Filter with :odd, .filter(":odd"), or .odd().
Step 3Remember: index 1 is the second element.

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

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.

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.

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.

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

11 people found this page helpful