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 DESCRIPTIONSIMPLE SELECTORSThe following selectors are the most basic, commonly used selectors.#idName
div#idNameSelects 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
.classNameSelects 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.titleSelects one or more elements by chaining multiple
selectors together with commas.HIERARCHYThe following selectors are used based on hierarchical context.div.outerContainer
table.formSelects 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.