Selector -> :even used to select even occurances of the element.

Now suppose we are creating a list and want to apply different styles to odd and even items of the list then we can us the following syntax:


The above line selects the even list items. This can be understood by the following example:

<!--program starts-->


<script type='text/javascript'>

$("li:even").css("color","#f11"); //makes the text color "red"





<!--program ends-->

So the above program changes the color of content or text of the even list items into "red".
Means it shows the numbers 2,4, and 6 in red color and others in black color(i.e. 1,3, and 5).

It affects all even li tag content of our page and have no effect on odd li tags' content of our page.

This selector is very powerful and mostly used when we want to make changes to the "tr" tags in a table to show difference between the table rows.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments