jQuery :even Selector

The jQuery :even selector selects the even elements of the matching tag name of HTML. The tag name elements can a table, list or any other group element.

jQuery :even Selector

Syntax

Let’s find out the way of using the selector with the syntax given below.

Syntax
$(“:even”)

Use jQuery :even Selector to Select Even Rows of a Table

If you are using it for HTML table to add CSS to alternate even tr rows of a table. The jQuery :even selector selects the even tr rows starting from the even index(like 0, 2, 4, etc.).

See the below example to select the even rows of a table and add color to the text.

Example

Test it Live

Output

Sr No Cricketer Name Score
1 Sanath Jayasuriya 187*
2 Arjuna Ranatunga 123
3 Mahela Jayawardana 141*

When you click the button given in the above example, it applies the red color to alternate even rows. This uses the jQuery :even selector to select the even tr to apply the color effect.

The above example selects the even tr elements of the table. However, you can also select the even list elements using the example given below.

Select Even List Element

Example

Test it Live

Output


  • jQuery is the scripting langauge.
  • You can apply sliding effect using jQuery.
  • Create an animatio effect using jQuery.
  • Add fading effect to an element with jQuery
  • Select required element in a webpage and apply effect using jQuery.

Click the button given in the example above to select the even list elements. It applies the red color to the list elements with indexes 0, 2 and 4.