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:

$("li:even")

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

<!--program starts-->

<html>

<head>
<script type='text/javascript'>

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

</script>
</head>

<body>

<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>

</body>
</html>

<!--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
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments