:odd Selector - Javascript jQuery Selector

Javascript examples for jQuery Selector:odd

Description

The :odd selector selects each element with an odd index number (like: 1, 3, 5, etc.).

The index numbers start at 0.

Syntax

The following code shows how to select every other (odd) <tr> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("tr:odd").css("background-color", "yellow");
});/*from   w ww  . j  a v a  2 s  . com*/
</script>
</head>
<body>

<h1>Welcome to My Web Page</h1>

<table border="1">
  <tr>
    <th>Company</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>A</td>
    <td>G</td>
  </tr>
  <tr>
    <td>C</td>
    <td>D</td>
  </tr>
  <tr>
    <td>E</td>
    <td>G</td>
  </tr>
  <tr>
    <td>E</td>
    <td>A</td>
  </tr>
  <tr>
    <td>I</td>
    <td>U</td>
  </tr>
</table>

</body>
</html>

Related Tutorials