.odd() JQ Home  <<  Filtering  <<  .even()

Filter elements.

Description

The .odd() method is used to reduce the matched set to the odd elements, starting at zero.

The .odd() method was added in jQuery 3.5

Syntax

Signature Description
.odd()Reduce the matched set to the odd elements, starting at zero.

Parameters

None.

Return

A jQuery object containing the filtered elements.

.odd() Example  Filtering  <<  Top

Reduce the matched set to the odd elements, starting at zero.

In the example we select all odd 'td' elements and change the background colour to purple.

Table For Testing The .odd() Signature
Table Row 1, Table Data 1 Table Row 1, Table Data 2
Table Row 2, Table Data 1 Table Row 2, Table Data 2



$(function(){
  $('#btn22').on('click', function() {
    $('.testtable td').odd()
                      .css('backgroundColor', 'purple');
  });
});


Press the button below to action the above code:

Related Tutorials

jQuery Intermediate Tutorials - Lesson 1 - Filtering Elements