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

Filter elements.

Description

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

The .even() method was added in jQuery 3.5

Syntax

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

Parameters

None.

Return

A jQuery object containing the filtered elements.

.even() Example  Filtering  <<  Top

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

In the example we select all even 'td' elements and change the background colour to orange.

Table For Testing The .even() 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(){
  $('#btn21').on('click', function() {
    $('.testtable td').even()
                      .css('backgroundColor', 'orange');
  });
});


Press the button below to action the above code:

Related Tutorials

jQuery Intermediate Tutorials - Lesson 1 - Filtering Elements