.odd()Returns: jQuery

Description: Reduce the set of matched elements to the odd ones in the set, numbered from zero.

  • version added: 3.5.odd()

    • This method does not accept any arguments.

Given a jQuery object that represents a set of DOM elements, the .odd() method constructs a new jQuery object from the odd elements in that set. Counting starts from zero!

Consider a page with a simple list on it:

  <li>list item 1</li>
  <li>list item 2</li>
  <li>list item 3</li>
  <li>list item 4</li>
  <li>list item 5</li>

We can apply this method to the set of list items:

$( "li" ).odd().css( "background-color", "red" );

The result of this call is a red background for the second & 4th items.


Highlight the odd items in a list.

<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <title>odd demo</title>
  .highlight {
    background-color: yellow;
  <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
  <li>This is some text in a list.</li>
  <li>This is a note about it.</li>
  <li>This is another note about it.</li>
$( "ul li" ).odd().addClass( "highlight" );


© The jQuery Foundation and other contributors
Licensed under the MIT License.