jQuery :odd Selector

Last Updated : 28 Jul, 2025

jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript. Elaborating the terms, it simplifies HTML document traversing and manipulation, browser event handling, DOM animations, Ajax interactions, and cross-browser JavaScript development.

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

Syntax: 

$(":odd")

Example 1: In this example, we are using the above-explained selector.

HTML

<html>

<head>
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
    script>
    <script>
        $(document).ready(function () {
            $("tr:odd").css("background-color",
                "green");
        });
    script>
head>

<body>
    <center>
        <h1>GeeksForGeeksh1>
        <table border="1">
            <tr>
                <th>Companyth>
                <th>Countryth>
            tr>
            <tr>
                <td>reliancetd>
                <td>Indiatd>
            tr>
            <tr>
                <td>flipkarttd>
                <td>Indiatd>
            tr>
            <tr>
                <td>walmarttd>
                <td>Americantd>
            tr>
            <tr>
                <td>Ernst Handletd>
                <td>Austriatd>
            tr>
            <tr>
                <td>Island Tradingtd>
                <td>UKtd>
            tr>
        table>
    center>
body>

html>

Output: 

Example 2: In this example, we are using the above-explained selector.

HTML

<html>

<head>
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
    script>
    <script>
        $(document).ready(function () {
            $("tr:odd").css("background-color",
                "lightgreen");
        });
    script>
head>

<body>
    <center>
        <h1>Welcome To GeeksForGeeksh1>
        <table border="2">
            <tr>
                <th>Stateth>
                <th>Capitalth>
            tr>
            <tr>
                <td>uttar pradeshtd>
                <td>lucknowtd>
            tr>
            <tr>
                <td>punjabtd>
                <td>chandigarhtd>
            tr>
            <tr>
                <td>haryanatd>
                <td>candigarhtd>
            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
Comment

Explore