</>
Skip to content
jQuery lessons (37/39)

jQuery — Selectors Reference

Basic Selectors

SelectorExampleDescription
*$("*")All elements
#id$("#demo")Element with id="demo"
.class$(".box")Elements with class="box"
element$("p")All p elements

Hierarchical Selectors

SelectorExampleDescription
descendant$("div p")p inside div
child$("div > p")Direct child p
next$("div + p")Adjacent p
siblings$("div ~ p")Following p siblings

Attribute Selectors

SelectorExampleDescription
[attr]$("[href]")Has href
[attr=val]$("[type='text']")Equals value
[attr!=val]$("[type!='text']")Not equals
[attr^=val]$("[href^='https']")Starts with
[attr$=val]$("[href$='.pdf']")Ends with
[attr*=val]$("[title*='hi']")Contains

Filter Selectors

SelectorExampleDescription
:first$("p:first")First p
:last$("p:last")Last p
:eq(n)$("p:eq(2)")Nth (0-indexed)
:odd$("tr:odd")Odd rows
:even$("tr:even")Even rows
:not(s)$("p:not(.skip)")Not matching
:gt(n)$("p:gt(2)")Greater than index
:lt(n)$("p:lt(2)")Less than index

Content Filters

SelectorDescription
:contains(text)Contains text
:emptyNo children
:has(selector)Has descendant
:parentHas children

Form Selectors

SelectorDescription
:inputAll form elements
:textText inputs
:passwordPassword inputs
:checkboxCheckboxes
:radioRadio buttons
:submitSubmit buttons
:selectedSelected options
:checkedChecked inputs
:disabledDisabled elements
:enabledEnabled elements

Mini Practice

  1. Test each basic selector type
  2. Use attribute selectors
  3. Filter elements with :eq and :not
  4. Select form elements

Up Next

Continue with Events Reference — complete list of jQuery events.

Related Topics

Frequently Asked Questions about Selectors Reference

What is Selectors Reference in jQuery?

Selectors Reference is a fundamental concept in jQuery. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Selectors Reference?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Selectors Reference.

Why is Selectors Reference important in jQuery?

Selectors Reference is essential for jQuery development. Understanding this concept will help you write better code and solve real-world problems more effectively.