jQuery :odd Selector

jQuery | :odd Selector: Learn about the jQuery :odd Selector with its usages, syntax, and examples.
Submitted by Pratishtha Saxena, on November 03, 2022

:odd Selector

In jQuery, selectors are a parameter through which we can select the HTML element. Selectors can comprise – class names, ids, tag names, attributes, etc. Basically, by using selectors, the appropriate HTML-DOM element can be selected and hence performed actions on it. Here, we are discussing the jQuery :odd Selector.

The jQuery :odd selector helps to select the odd indexed occurrence of the specified tag. It returns the elements at an odd index i.e., 1,3,5,7….. It is used along with some tag name prepended to it, generally in a table (<tr>). It selects the odd indexed value in the table.

:odd Selector Syntax


Once the element is selected, you can access it and perform the actions that you want to perform on it. The example given below shows the selection of the odd indexed elements of the table on click by passing the appropriate selector.

jQuery :odd Selector Example

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
      border: 2px solid olive;
    <h2>jQuery - :odd Selector</h2>
    <p>Click the button to Select the odd indexed elements of the following table.</p>
    <button>:odd Selector</button>
    <table border="2">
        <th>Heading 1</th>
        <th>Heading 2</th>
        <td>Data 1</td>
        <td>Data 2</td>
        <td>Data 3</td>
        <td>Data 4</td>
        <td>Data 5</td>
        <td>Data 6</td>
        <td>Data 7</td>
        <td>Data 8</td>
        <td>Data 9</td>
        <td>Data 10</td>
  <script type="text/javascript">
            $('h3').html('Odd Indexed Data Highlighted')


Example 1: jQuery :odd Selector

Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.