The Wayback Machine - https://web.archive.org/web/20241127003513/https://www.geeksforgeeks.org/jquery-even-selector/
Open In App

jQuery :even Selector

Last Updated : 11 Jul, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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 on the terms, it simplifies HTML document traversing and manipulation, browser event handling, DOM animations, Ajax interactions, and cross-browser JavaScript development.

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

Syntax 

$(":even")

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

HTML




<!DOCTYPE html>
<html>
 
<head>
    <script src=
    </script>
    <script>
        $(document).ready(function () {
            $("tr:even").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:even").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>chandigarh</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


Previous Article
Next Article

Similar Reads

jQuery :input Selector
The jQuery :input selector in jQuery is used to select input elements. This selector is also used with button element. Syntax: $(":input")Note: jQuery :input selector not only selects input elements but also Buttons, Dropdowns, and Textarea elements. Example 1: This example use :input selector to count all input elements. C/C++ Code <!DOCTYPE ht
2 min read
jQuery :nth-of-type() Selector
The :nth-of-type() is an inbuilt selector in jQuery, used to select all the nth-child elements of the specified parent. Syntax: parent_name : nth-of-type(n|even|odd|algebraic equation)Parameters: It takes a parameter n | even | odd | algebraic equation. ValueDescriptionnSelect the child present at nth index (starting from 1). n must be an integer.e
3 min read
jQuery :enabled Selector
The jQuery :enabled selector is used to select all enabled form elements. Syntax : $(":enabled")Parameter: :enabled selector: It is used for selecting HTML elements that support the disabled attribute. i.e button tag, input tag, optgroup tag, option tag, select tag and textarea tag.Example 1: C/C++ Code <!DOCTYPE html> <html> <head
1 min read
jQuery element Selector
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 developm
1 min read
jQuery :last Selector
The jQuery :last Selector is used to select the last element of the specified type. Syntax: $(":last")Example 1: In this example, we will select the last <p> element by using jQuery :last Selector. C/C++ Code <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
1 min read
jQuery :button Selector
The jQuery :button selector selects button elements and input elements with type="button". The button element is not selected if we use input=" button" as a selector. Syntax: $(":button") Example 1: In this example, we are using jQuery: button Selector. C/C++ Code <!DOCTYPE html> <html> <head> <title>jQuery :button Selector
1 min read
jQuery :animated Selector
The jQuery :animated Selector is an inbuilt selector which is used to select the element that is currently animated. Syntax: $(:animated)Below examples illustrate the animated selector in jQuery: Example 1: In this example, we will select the animated element by using jQuery animated Selector. C/C++ Code <!DOCTYPE html> <html> <head
2 min read
jQuery :header Selector
The jQuery :header Selector is used to select all the heading elements that are from (<h1> to <h6>). Syntax: $(":header") Example 1: Change the color of all headings to green. C/C++ Code <!DOCTYPE html> <html> <head> <title>jQuery :header Selector</title> <script src= "https://ajax.googleapis.com/aj
1 min read
jQuery #id Selector
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 on the terms, it simplifies HTML document traversing and manipulation, browser event handling, DOM animations, Ajax interactions, and cross-browser JavaScript devel
1 min read
jQuery .class Selector
The jQuery .class selector specifies the class for an element to be selected. It should not begin with a number. It gives styling to several HTML elements. Syntax: $(".class") Parameter: class: This parameter is required to specify the class of the elements to be selected.Example 1: In this example, we will select a class by using jQuery .class Sel
1 min read
jQuery :text Selector
The jQuery :text Selector is used to select input element with having a text field i.e (type==text). Syntax: $(":text") Example 1: In this example, we will select the input element that has a text field by using jQuery :text Selector. C/C++ Code <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/l
1 min read
jQuery :password Selector
The jQuery :password Selector is used to select the input element having password field . i.e (type==password) Syntax: $(":password")Example 1: In this example, we will select the input element which has a password field by using jQuery :password Selector. C/C++ Code <!DOCTYPE html> <html> <head> <script src= "https://ajax
1 min read
jQuery :file Selector
The jQuery :file Selector is used to selects the input element having file field.(type==file) Syntax: $(":file")Example 1: In this example, we will select the input element with type = file. C/C++ Code <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
1 min read
jQuery :submit Selector
The jQuery :submit Selector is an inbuilt selector which is used to select the submit button and input element having submitted type field. If the type of button is undefined, most of the standard browsers use it as type="submit". Syntax: $(":submit")Example 1: In this example, we will select the input element which has a submit field button by usi
2 min read
jQuery :checked Selector
The jQuery :checked selector is used to select all checked checkboxes, radio buttons, and options of select elements. Note: To retrieve only the selected options of select elements, use:selected selector. Syntax: $(":checked")The below examples illustrate the : checked selector in jQuery: Example 1: This example applies CSS to all checked elements(
2 min read
jQuery :reset Selector
The jQuery :reset Selector is used to select the input element having a reset field button.i.e <input type="button">. Syntax: $(":reset")Example 1: In this example, we will select the input element which has a reset field button by using jQuery :reset Selector. C/C++ Code <!DOCTYPE html> <html> <head> <script src= "h
1 min read
jQuery :selected Selector
The jQuery :selected selector is used to select option elements that are pre-selected. Note: To retrieve only the check-boxes or radio buttons, use the :checked selector. Syntax: $(":selected")Below are examples that illustrate the :selected selector in jQuery: Example 1: This example uses CSS property to all pre-selected elements. The background-c
2 min read
jQuery :disabled Selector
The jQuery :disabled selector is used for selecting all disabled form elements. Syntax: $(":disabled")Parameter: :disabled selector: It is used for selecting HTML elements that support the disabled attribute. i.e. button tag, input tag, outgroup tag, option tag, select tag, and textarea tag.Example 1: C/C++ Code <!DOCTYPE html> <html>
1 min read
jQuery :first-of-type Selector
The jQuery :first-of-type Selector is used to select all elements that are the first child, of a particular type, of their parent. Syntax: $(":first-of-type")The below examples illustrate the:first-of-type selector in jQuery: Example 1: This example changes the background color to green and the text color to white, of the first heading of their par
2 min read
jQuery :last-of-type Selector
The jQuery :last-of-type Selector is used to select all elements which are the last child of their parent. Syntax: $(":last-of-type") Below are examples that illustrate the :last-of-type selector in jQuery: Example 1: This example changes the background-color to green and text-color to white, of the last element of their parents (div tags). C/C++ C
2 min read
jQuery :nth-last-child() Selector
The jQuery :nth-last-child() selector is used to select all elements that are the nth last child of their parent. The counting of elements starts from the last element. Syntax: :nth-last-child( n | even | odd | formula )Parameters: The :nth-last-child() selector contain parameters which are listed below: n: It holds the child index number of the se
2 min read
jQuery :odd Selector
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 developm
2 min read
jQuery :checkbox Selector
The jQuery :checkbox Selector is a very important element to make interactions with a user. In JQuery, we can build a simple checkbox to allow data entry as well. Syntax: $(":checkbox")We can implement the checkbox in the code: Example 1: In this example, we will select the input element which has a checkbox field button by using jQuery :checkbox S
1 min read
jQuery :radio Selector
The jQuery :radio Selector is used to select all elements of type radio. The working of $( “:radio” ) and $( “[type=radio]” ) is same. To select a group of radio buttons that are used in the form, we use $( "input[name=name_of_group]:radio" ). It returns an array of input elements of type radio. Syntax: Default Syntax: $( "input[name=group_name]:ra
2 min read
jQuery multiple elements Selector
The jQuery multiple elements Selector is used to select multiple elements of an HTML document. Syntax: $("element1, element2, element3, ...")Parameter: element: This parameter is required to specify the elements to be selected.Example 1: In this example, we will select the multiple elements by using jQuery multiple elements Selector. C/C++ Code
1 min read
jQuery [attribute!=value] Selector
The jQuery [attribute!=value] selector in jquery is used to select each element that doesn't have the specified attribute and value. Syntax: $("[attribute!='value']")Parameter: attribute: This parameter is required to specify the attribute to be searched.value: This parameter is required to specify the value to be searched.Example 1: C/C++ Code
1 min read
jQuery :focus Selector
The jQuery :focus Selector is used to select all the elements that have focus on the document currently. It is also used with a tag name or using another selector. Syntax: $(":focus")Example 1: C/C++ Code <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
1 min read
jQuery :lang() Selector
The jQuery :lang Selector is used to select all the elements which have the lang attribute with the specified value. This attribute contains single value language_code which is used to specify the language of content. Some examples of languages are " en" for English, "es" for Spanish etc. It takes a whole word as value such as lang=” en” or followe
2 min read
jQuery [attribute*=value] Selector
jQuery ("[attribute*=value]") Selector is used to select all elements with attribute specified by attribute parameter that contains the word specified by the value parameter. Syntax: $("[attribute*='value']")Parameters: This selector has two parameters. attribute: attribute specifies the attributes that need to find.value: value is the string that
2 min read
jQuery :empty Selector
The :empty selector in jQuery is used to select empty elements. Syntax: $(":empty")Parameter: The :empty selector contains a single parameter empty which is mandatory and used to select an empty element which is an element without child elements or text. Example 1: This example uses :empty selector to select an element position in a table. C/C++ Co
2 min read
three90RightbarBannerImg