Selector expressions
The jQuery factory function $()
is used to find elements on the page to work with. This function takes a string composed of CSS-like syntax, called a selector expression. Selector expressions are discussed in detail in Chapter 2, Selecting Elements.
Simple CSS
Selector |
Matches |
---|---|
|
All elements. |
|
The element with the given ID. |
|
All elements of the given type. |
|
All elements with the given class. |
|
Elements that are matched by |
|
Elements |
|
Elements |
|
Elements |
|
Elements
|
Position among siblings
Selector |
Matches |
---|---|
|
Elements
that are the |
|
Elements that are an even child of their parent element (1-based). |
|
Elements which are an odd child of their parent element (1-based). |
|
Elements that are the nth child of their parent element (1-based). Formulas are of the form |
|
The same as |
|
Elements that are the first child of their parent. |
|
Elements that are the last child of their parent. |
|
Elements that are the only child of their parent. |
|
The same as |
|
The same as |
|
Elements which are the first child of the same element name among their siblings. |
|
Elements that are the last child of the same element name among their siblings. |
|
Elements that are the only child of the same element name among their siblings. |
Position among matched elements
Selector |
Matches |
---|---|
|
The first element in the result set. |
|
The last element in the result set. |
|
All elements in the result set that are not matched by |
|
Even elements in the result set (0-based). |
|
Odd elements in the result set (0-based). |
|
A numbered element in the result set (0-based). |
|
All elements in the result set after (greater than) the given index (0-based). |
|
All elements in the result set before (less than) the given index (0-based). |
Attributes
Selector |
Matches |
---|---|
|
Elements that have the attribute |
|
Elements whose |
|
Elements whose
|
|
Elements whose |
|
Elements whose |
|
Elements whose |
|
Elements whose |
|
Elements whose
|
Forms
Selector |
Matches |
---|---|
|
All
|
|
The |
|
The
|
|
The
|
|
The |
|
The |
|
The |
|
The
|
|
The |
|
The |
|
Enabled form elements. |
|
Disabled form elements. |
|
Checked checkboxes and radio buttons. |
|
Selected
|
Miscellaneous selectors
Selector |
Matches |
---|---|
|
The root element of the document. |
|
Header elements (for example, |
|
Elements with an animation in progress. |
|
Elements containing the given text. |
|
Elements with no child nodes. |
|
Elements containing a descendant element matching |
|
Elements that have child nodes. |
|
Elements that are hidden, either through CSS or because they are |
|
The inverse of |
|
The element that has the keyboard focus. |
|
Elements with the given language code (either due to a |
|
Whichever element is targeted by the URI's fragment identifier, if any. |