Home >>jQuery Tutorial >jQuery :odd Selector

jQuery :odd Selector

jQuery :odd Selector

jQuery :odd selector in jQuery is used to selects each element with an odd index number (like: 1, 3, 5, etc.) and starts at 0 index number.

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

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("tr:odd").css("background-color", "lightgreen");
});
</script>
</head>
<body>
<table border="1">
<tr>
<th>S.no</th>
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>Mexico</td>
</tr>
<tr>
<td>2</td>
<td>India</td>
</tr>
<tr>
<td>3</td>
<td>Australia</td>
</tr>
<tr>
<td>4</td>
<td>Germany</td>
</tr>
<tr>
<td>5</td>
<td>UK</td>
</tr>
</table>
</body>
</html>

Output:
S.no Country
1 Mexico
2 India
3 Australia
4 Germany
5 UK

No Sidebar ads