Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

jQuery | :odd Selector

  • Last Updated : 30 Sep, 2021

The jQuery :odd selector used to select an odd number index from the elements. The number of index starts from 0. The working is same as :even selectors but for odd numbers.

Syntax 

$(":odd")

Example-1: 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <script src=
  </script>
     
  <script>
        $(document).ready(function() {
            $("tr:odd").css("background-color",
                            "green");
        });
    </script>
</head>
 
<body>
 
    <center>
        <h1>GeeksForGeeks</h1>
 
        <table border="1">
            <tr>
                <th>Company</th>
                <th>Country</th>
            </tr>
            <tr>
                <td>reliance</td>
                <td>India</td>
            </tr>
            <tr>
                <td>flipkart</td>
                <td>India</td>
            </tr>
            <tr>
                <td>walmart</td>
                <td>American</td>
            </tr>
            <tr>
                <td>Ernst Handle</td>
                <td>Austria</td>
            </tr>
            <tr>
                <td>Island Trading</td>
                <td>UK</td>
            </tr>
        </table>
    </center>
 
</body>
 
</html>

Output: 



Example-2: 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <script src=
  </script>
    
  <script>
    $(document).ready(function() {
       $("tr:odd").css("background-color",
                    "lightgreen");
        });
    </script>
</head>
 
<body>
 
    <center>
        <h1>Welcome To GeeksForGeeks
      </h1>
 
        <table border="2">
            <tr>
                <th>State</th>
                <th>Capital</th>
            </tr>
            <tr>
                <td>uttar pradesh</td>
                <td>lucknow</td>
            </tr>
            <tr>
                <td>punjab</td>
                <td>chandigarh</td>
            </tr>
            <tr>
                <td>haryana</td>
                <td>candigarh</td>
            </tr>
        </table>
    </center>
 
</body>
 
</html>

Output: 

Supported Browsers: 

  • Google Chrome 90.0+
  • Internet Explorer 9.0
  • Firefox 3.6
  • Safari 4.0
  • Opera 10.5

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :