English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery :even Even Selector

jQuery Selectors

:even selector selects each element with an even index number (for example: 0,2,4)

Index numbers start from 0, so the index number of the first element is 0 (not1)

This is usually used with another selector to select each even-indexed element in the group (as shown in the following examples).

Use:oddSelector selects elements with odd index numbers.

Syntax:

$":even")

Example

Select even table rows, match the first, third, etc. (indexes 0,2,4and so on):

$("document").ready(function(){
  $("tr:even").css("background", "coral");
});
Test and See‹/›

Select even list items, match the first, third, etc. (indexes 0,2,4and so on):

$("document").ready(function(){
  $("li:even").css("background", "coral");
});
Test and See‹/›

jQuery Selectors