Advertisement

Google Ad Slot: content-top

jQuery Selectors

~1 min read · JQuery
On this page

jQuery selectors are used to "find" or "select" HTML elements, so you can apply actions to them — like hiding, showing, changing text, animating, and more.


jQuery selectors use the same syntax as CSS selectors, so if you know CSS, this will feel familiar!


All selectors in jQuery start with the dollar sign and parentheses: $().

Basic jQuery Selectors


Selector Type

Description

Example

Element

Selects all <p> elements

ID

Selects the element with ID myId

Class

Selects all elements with class myClass

Universal

Selects all elements

Group

Selects all<h1> and <p> elements

Advanced Selectors

Selector

Description

Example

$("p:first")

Selects the first<p> element

$("p:last")

Selects the last<p> element

$("li:even")

Selects even-numbered<li> elements

$("li:odd")

Selects odd-numbered<li> elements

$("ul li:first")

Selects the first <li> element of the first <ul>

$("ul li:first-child")

Selects the first <li> element of every <ul>

$("[href]")

Selects elements with an href attribute

$("[href='#']")

Selects elements with href="#"

$("[href^='https']")

hrefstarts withhttps

$("[href$='.com']")

hrefends with.com