jQuery Selectors

Beginner
10 min read
Updated: Nov 2026
62 method guides
Method index

About This Index

This page is the jQuery Selectors index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.

Learn the jQuery overview on /jquery. Use this page when you need a selector such as #id, .class, or :checked.

Beginner path.

Start with #id, .class, and tag selectors, then combinators (>, space, +, ~)—add attribute and form filters as needed.

How to Call a Selector

Pass a selector string to $() — escape special characters in IDs/classes with \\:

jQuery
$("#app");                            // ID
$(".card");                           // class
$("p");                               // element
$("ul > li");                         // child
$("form input");                      // descendant
$("input[type='text']");              // attribute
$("input:checked");                   // form state
$("tr:even");                         // basic filter
$("#foo\\.bar");                      // escaped ID with a dot

$(".item").length;                    // match count

jQuery Selectors Table

All Selectors guides in this jQuery tutorial series (62 tutorials).

Basic Selectors

5 methods

Start here — match by tag, id, class, universal *, or comma-separated unions.

MethodDescriptionTutorial
Element Selector ("element")Select all elements with a given HTML tag name — official div demo since jQuery 1.0; uses getElementsByTagName; combine with .class or #id for precision.Try it
ID Selector ("#id")Select a single element by id attribute — official #myDiv border demo since jQuery 1.0; uses getElementById; escape dots and brackets in id values; zero or one match; combine with tag as h2#pageTitle.Try it
Class Selector (".class")Select all elements with a given CSS class — official .myClass demo; chain .a.b for AND; jQuery uses getElementsByClassName when supported since 1.0.Try it
All Selector ("*")Select every element in the document or within a scoped container — the universal jQuery selector since 1.0.Try it
Multiple Selector ("selector1, selector2, selectorN")Combine selectors with comma OR logic — official div, span, p.myClass border demo since jQuery 1.0; union of disparate elements; result order is document order; alternative .add() method; standard CSS.Try it

Hierarchy & Combinators

4 methods

Relate elements by DOM structure — child, descendant, adjacent, and general siblings.

MethodDescriptionTutorial
Child Selector ("parent > child")Match direct children only with the > combinator — official ul.topnav > li demo; stricter than the descendant (space) combinator since jQuery 1.0.Try it
Descendant Selector ("ancestor descendant")Match elements at any nesting depth with the space combinator — official form input demo since jQuery 1.0; broader than the child (>) combinator.Try it
Next Adjacent Selector ("prev + next")Match the immediate next sibling — official label + input demo since jQuery 1.0; adjacent sibling combinator (+); one element only; same parent required; stricter than general sibling (~).Try it
Next Siblings Selector ("prev ~ siblings")Match all following siblings — official #prev ~ div demo since jQuery 1.0; general sibling combinator (~); broader reach than adjacent (+); gaps between siblings do not break the match; same parent required.Try it

Attribute Selectors

9 methods

Target elements by HTML attribute names and values.

MethodDescriptionTutorial
Has Attribute Selector [name]Match elements that have a named attribute with any value — official div[id] one-click demo since jQuery 1.0; foundation before [name="value"] exact matching; standard CSS.Try it
Attribute Equals [name="value"]Match attribute values exactly equal to a given string — the foundational exact-match selector for types, names, and fixed tokens since jQuery 1.0.Try it
Attribute Not Equal [name!="value"]Exclude one exact attribute value — jQuery extension since 1.0 that also matches elements without the attribute; prefer .not() for performance.Try it
Attribute Contains Prefix [name|="value"]Match attribute values equal to a string or starting with that string followed by a hyphen — ideal for language codes like en and en-US.Try it
Attribute Contains [name*="value"]Match elements whose attribute value contains a substring anywhere — the most flexible jQuery attribute value selector since 1.0.Try it
Attribute Contains Word [name~="value"]Match when a space-separated word in the attribute value exactly equals the search string — ideal for class lists and token attributes.Try it
Attribute Starts With [name^="value"]Match attribute values that begin exactly with a given string — case-sensitive prefix matching for URL schemes and field naming patterns since jQuery 1.0.Try it
Attribute Ends With [name$="value"]Match attribute values that end exactly with a given string — case-sensitive suffix matching for extensions and naming patterns since jQuery 1.0.Try it
Multiple Attribute [name="value"][name2="value2"]Chain attribute filters with AND logic — official input[id][name$='man'] demo since jQuery 1.0; match elements satisfying all filters; combine presence [id] with = ^ $ * operators; standard CSS.Try it

Form Selectors

15 methods

Match form controls and their live state — input types, checked, enabled, and focus.

MethodDescriptionTutorial
:input SelectorSelect all form controls — input, textarea, select, and button elements — official count vs form children demo since jQuery 1.0; jQuery extension; not the same as input tag selector; prefer form :input or .filter(":input") for performance.Try it
:text SelectorSelect all input[type=text] elements — jQuery form pseudo-class since 1.0; since 1.5.2 also matches bare input without type attribute; prefer input:text over bare :text; differs from [type=text] on no-type inputs; use input[type='text'] for native performance.Try it
:password SelectorSelect all input[type=password] fields — prefer input:password over bare :password.Try it
:checkbox SelectorSelect all input[type=checkbox] elements — jQuery form pseudo-class since 1.0; prefer input:checkbox over bare :checkbox; CSS equivalent is input[type='checkbox'].Try it
:radio SelectorSelect all input[type=radio] elements — jQuery form pseudo-class since 1.0; equivalent to [type=radio]; prefer input:radio over bare :radio; use input[name=group]:radio for one mutually exclusive group.Try it
:file SelectorSelect all input[type=file] upload controls — jQuery form pseudo-class since 1.0; equivalent to [type=file]; prefer input:file over bare :file; use input[type='file'] for native querySelectorAll performance.Try it
:image SelectorSelect all input[type=image] graphical submit controls — jQuery form pseudo-class since 1.0; equivalent to [type=image]; does not match img tags; prefer input:image over bare :image; use input[type='image'] for native performance.Try it
:button SelectorSelect button elements and input[type=button] controls — jQuery form pseudo-class since 1.0; CSS equivalent is button, input[type='button'].Try it
:submit SelectorSelect all submit-type form controls — input[type=submit] and button[type=submit] since jQuery 1.0; always specify type on buttons; official td :submit demo; native alternative input[type='submit'], button[type='submit'], button:not([type]).Try it
:reset SelectorSelect all input[type=reset] form reset controls — jQuery form pseudo-class since 1.0; equivalent to [type=reset]; prefer input:reset over bare :reset; use input[type='reset'] for native querySelectorAll performance.Try it
:checked SelectorMatch currently checked checkboxes, selected radio buttons, and chosen option elements — live state filter since jQuery 1.0; combine with :checkbox for ticked boxes only.Try it
:selected SelectorMatch selected option elements in select dropdowns — jQuery extension since 1.0; does not apply to checkboxes or radios (use :checked); official change demo with option:selected; prefer .filter(':selected') after a CSS option query.Try it
:enabled SelectorMatch form controls that are currently enabled — official input:enabled demo since jQuery 1.0; complement of :disabled; prefer over :not([disabled]) for live state; prefix with input or button, not bare :enabled.Try it
:disabled SelectorMatch form controls that are actually disabled — official input:disabled demo since jQuery 1.0; prefer over [disabled] for live state; prefix with input or button, not bare :disabled.Try it
:focus SelectorMatch elements that currently have focus — official delegate focus/blur demo since jQuery 1.6; prefix with input or button, not bare :focus; prefer document.activeElement for a single global lookup; standard CSS.Try it

Basic Filters

13 methods

Narrow a matched set by index or position — prefer .eq() / .first() methods in modern jQuery.

MethodDescriptionTutorial
:first SelectorSelect the first element in the matched set — official tr:first demo since jQuery 1.0; equivalent to :eq(0) and :lt(1); single match vs many for :first-child; deprecated in 3.4 — prefer .first() method.Try it
:last SelectorSelect the last element in the matched set — official tr:last demo since jQuery 1.0; equivalent to :eq(-1); single match vs many for :last-child; deprecated in 3.4 — prefer .last() method.Try it
:eq() SelectorSelect one element at a zero-based index in the matched set — official td:eq(2) demo since jQuery 1.0; negative indices since 1.8; deprecated in 3.4 — prefer .eq() method instead.Try it
:gt() SelectorSelect elements after a zero-based index in the matched set — official td:gt(4) and td:gt(-2) demo since jQuery 1.0; negative indices since 1.8; deprecated in 3.4 — prefer .slice(index + 1) instead.Try it
:lt() SelectorSelect elements before a zero-based index in the matched set — official td:lt(4) and td:lt(-2) demo since jQuery 1.0; :lt(1) equals :first; negative indices since 1.8; deprecated in 3.4 — prefer .slice(0, index) instead.Try it
:even SelectorSelect elements at even zero-based indices (0, 2, 4…) in the matched set — official tr:even zebra demo since jQuery 1.0; pair with :odd; deprecated in 3.4 — prefer .even() method (3.5+).Try it
:odd SelectorSelect elements at odd zero-based indices (1, 3, 5…) — pair with :even; prefer .odd() in jQuery 3.5+.Try it
:not() SelectorExclude elements that match the given selector — keep everything else in the set.Try it
:header SelectorSelect all heading elements h1 through h6 in one expression — official page-wide .css() demo since jQuery 1.2; jQuery extension; CSS equivalent is h1, h2, h3, h4, h5, h6; prefer .filter(":header") after a CSS scope for performance.Try it
:animated SelectorSelect elements currently running a jQuery animation — slide, fade, show/hide effects — since jQuery 1.2.Try it
:root SelectorSelect the document root element — exactly one node; in HTML always the html element since jQuery 1.9; equivalent to $('html') and document.documentElement; standard CSS pseudo-class also works in querySelector.Try it
:target SelectorSelect the element indicated by the URL hash fragment — id matching the URI fragment identifier since jQuery 1.9; official example p:target for #foo; standard CSS pseudo-class; use hashchange to update on navigation.Try it
:lang() SelectorMatch elements by language code from the lang attribute or inherited language — official div:lang(en-us) and div:lang(es-es) color demo since jQuery 1.9; standard CSS; :lang(en) matches en and en-US prefix variants; differs from exact [lang="en"].Try it

Child Filters

10 methods

Match by sibling position among a parent’s children.

MethodDescriptionTutorial
:first-child SelectorSelect elements that are the first child of their parent — official div span:first-child demo since jQuery 1.1.4; can match multiple elements; equivalent to :nth-child(1); standard CSS.Try it
:last-child SelectorSelect elements that are the last child of their parent — official div span:last-child demo since jQuery 1.1.4; can match multiple elements; equivalent to :nth-last-child(1); standard CSS; differs from .last() which returns one element.Try it
:only-child SelectorSelect elements that are the only child of their parent.Try it
:nth-child() SelectorMatch elements that are the nth child of their parent — supports numbers, even/odd, and formulas.Try it
:nth-last-child() SelectorLike :nth-child, but count from the last child toward the first.Try it
:first-of-type SelectorSelect the first element of each tag name among siblings — official span:first-of-type demo since jQuery 1.9; differs from :first-child when mixed element types precede the target; equivalent to :nth-of-type(1); standard CSS.Try it
:last-of-type SelectorSelect the last element of each tag name among siblings — official span:last-of-type demo since jQuery 1.9; differs from :last-child when mixed element types follow the target; equivalent to :nth-last-of-type(1); standard CSS.Try it
:only-of-type SelectorSelect elements with no siblings of the same element name.Try it
:nth-of-type() SelectorMatch the nth sibling with the same element name among its parent’s children.Try it
:nth-last-of-type() SelectorLike :nth-of-type, but count from the last matching sibling toward the first.Try it

Content Filters

4 methods

Match by text content or child presence.

MethodDescriptionTutorial
:contains() SelectorSelect elements whose visible text includes a case-sensitive substring — official div:contains('John') demo since jQuery 1.1.4; jQuery extension, not native CSS.Try it
:empty SelectorSelect elements with no child nodes (including text) — official td:empty demo since jQuery 1.0; inverse of :parent; prefix with td or div, not bare :empty; whitespace text nodes prevent a match.Try it
:has() SelectorSelect elements that contain at least one descendant matching an inner selector — official div:has(p) demo since jQuery 1.1.4; jQuery extension; prefer .has() method over :has() in selector strings for performance.Try it
:parent SelectorSelect elements that have at least one child node (element or text) — inverse of :empty.Try it

Visibility Filters

2 methods

Match elements that are currently shown or hidden in the layout.

MethodDescriptionTutorial
:visible SelectorSelect elements that consume layout space — width or height greater than zero — official div:visible click demo and div:hidden.show() reveal since jQuery 1.0; opposite of :hidden; visibility:hidden and opacity:0 are still :visible; all option elements are hidden; prefer .filter(":visible") after CSS scope.Try it
:hidden SelectorSelect elements that consume no layout space — display:none, type=hidden, zero size, or hidden ancestors — official count and div:hidden.show() demo since jQuery 1.0; opposite of :visible; visibility:hidden and opacity:0 are not :hidden; prefer .filter(":hidden") after CSS scope.Try it

Frequently Asked Questions

Selectors are strings passed to $() that tell jQuery which DOM elements to collect. They use CSS-style syntax—tags, classes, IDs, attributes, combinators, and jQuery extensions—and return a collection you can chain.
Start with #id, .class, and element (tag) selectors, then combinators (>, space, +, ~). Add attribute and form filters next; use :eq / :nth-child when you need index-based matching.
No. Many jQuery extensions (:checkbox, :visible, :eq, :contains, …) are not native CSS. Prefer CSS selectors when you can, or filter with .filter() after a fast CSS query.
Yes on large pages. Prefer specific IDs/classes, or scope with a parent: $('#box').find('*'). Count matches with .length.
Start with the ID and class selectors, then the child/descendant combinators. Open form and attribute guides when you need to match controls or HTML attributes.

Start with #id

Open the ID selector guide—syntax, examples, and FAQs.

#id tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

16 people found this page helpful