Web Development with jQuery®

(Elliott) #1

bapp02.indd 02/17/2015 Page 493


jQuery Selectors


The following table contains the selector syntax that you can use with jQuery’s Selector API,
which is implemented using the open source Sizzle engine.

SELECTOR DESCRIPTION

SIMPLE SELECTORS

The following selectors are the most basic, commonly used selectors.

#idName
div#idName

Selects a single element via the id name specifi ed in the
element’s id attribute.

div Selects one or more elements by the element name—
for example, form, div, input, and so on.

div.className
.className

Selects one or more elements via a class name present
in the element’s class attribute. Individual elements
may also have multiple class names.

* The universal or wildcard selector; selects all elements.

div.body, div.sideColumn,
h1.title

Selects one or more elements by chaining multiple
selectors together with commas.

HIERARCHY

The following selectors are used based on hierarchical context.

div.outerContainer
table.form

Selects one or more elements based on an ancestral
relationship.

div#wrapper > h1.title Selects one or more elements based on a parent, child
relationship.

h3 + p Selects the sibling immediately following an element.

h3 ~ p Selects any siblings immediately following an element.

B


http://www.it-ebooks.info

Free download pdf