jQuery Selectors

In jquery, selectors are used to select and manupulate the elements in the HTML Document.
Syntax $("h1")
By selecting it selects all the h1 tags in the HTML Document and can manupulate them.

Use of selectors in jQuery

Here are the selector types and its syntax in jQuery

Selector Type

Syntax

Description

Element Selector

$("p")

Selects all elements of a specific type (e.g., <p>).

ID Selector

$("#myId")

Selects a single element by its ID attribute.

Class Selector

$(".myClass")

Selects all elements with a specific class.

Attribute Selector

$("input[type='text']")

Selects elements based on the presence or value of attributes.

Descendant Selector

$("div p")

Selects all elements that are descendants of a specified element.

Child Selector

$("ul > li")

Selects all direct children of a specified element.

Sibling Selector

$("h2 + p")

Selects all elements that are siblings of a specified element.

:first Selector

$("p:first")

Selects the first matched element.

:last Selector

$("p:last")

Selects the last matched element.

:even Selector

$("tr:even")

Selects even elements.

:odd Selector

$("tr:odd")

Selects odd elements.



Quick Recap - Topics Covered

jQuery Selectors

Practice With Examples in Compilers

The Concepts and codes you leart practice in Compilers till you are confident of doing on your own. A Various methods of examples, concepts, codes availble in our websites. Don't know where to start Down some code examples are given for this page topic use the code and compiler.

Example js

Example 1 Example 2 Example 3 Example 4 Example 5


Quiz


FEEDBACK

Rating


Message