jQuery :even Selector

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

:even 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 :even Selector.

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

:even 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 even indexed elements of the table on click by passing the appropriate selector.

jQuery :even 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 - :even Selector</h2>
    <p>Click the button to Select the even indexed elements of the following table.</p>
    <button>:even 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('Even Indexed Data Highlighted')


Example 1: jQuery :even 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.