Home >>jQuery Tutorial >jQuery :even Selector

jQuery :even Selector

jQuery :even Selector

jQuery :even selector in jQuery is used to selects each element with an even index number (like: 0, 2, 4, etc.).

Syntax:
$(":even")
Here is an Example of jQuery :even Selector:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("tr:even").css("background-color", "lightgreen");
});
</script>
</head>
<body>
<table border="1">
<tr>
<th>Fname</th>
<th>Lname</th>
</tr>
<tr>
<td>Rahul</td>
<td>Singh</td>
</tr>
<tr>
<td>shyam</td>
<td>choudhary</td>
</tr>
<tr>
<td>Arjun</td>
<td>Paney</td>
</tr>
<tr>
<td>Mukesh</td>
<td>Soorayavanshi</td>
</tr>
</table>
</body>
</html>

Output:
Fname Lname
Rahul Singh
shyam choudhary
Arjun Paney
Mukesh Soorayavanshi