CARVIEW |
Selectors
Borrowing from CSS 1–3, and then adding its own, jQuery offers a powerful set of tools for matching a set of elements in a document.
If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^`{|}~
) as a literal part of a name, you must escape the character with two backslashes: \\
. For example, if you have an element with id="foo.bar"
, you can use the selector $("#foo\\.bar")
. The W3C CSS specification contains the complete set of rules regarding valid CSS selectors. Also useful is the blog entry by Mathias Bynens on CSS character escape sequences for identifiers.
-
All Selector (“*”)
BasicSelects all elements.
-
:animated Selector
Basic Filter, jQuery ExtensionsSelect all elements that are in the progress of an animation at the time the selector is run.
-
Attribute Contains Prefix Selector [name|="value"]
AttributeSelects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-).
-
Attribute Contains Selector [name*="value"]
AttributeSelects elements that have the specified attribute with a value containing the a given substring.
-
Attribute Contains Word Selector [name~="value"]
AttributeSelects elements that have the specified attribute with a value containing a given word, delimited by spaces.
-
Attribute Ends With Selector [name$="value"]
AttributeSelects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.
-
Attribute Equals Selector [name="value"]
AttributeSelects elements that have the specified attribute with a value exactly equal to a certain value.
-
Attribute Not Equal Selector [name!="value"]
Attribute, jQuery ExtensionsSelect elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value.
-
Attribute Starts With Selector [name^="value"]
AttributeSelects elements that have the specified attribute with a value beginning exactly with a given string.
-
:button Selector
Deprecated, Form, jQuery ExtensionsSelects all button elements and elements of type button.
-
:checkbox Selector
Deprecated, Form, jQuery ExtensionsSelects all elements of type checkbox.
-
:checked Selector
FormMatches all elements that are checked.
-
Child Selector (“parent > child”)
HierarchySelects all direct child elements specified by "child" of elements specified by "parent".
-
Class Selector (“.class”)
BasicSelects all elements with the given class.
-
:contains() Selector
Content FilterSelect all elements that contain the specified text.
-
Descendant Selector (“ancestor descendant”)
HierarchySelects all elements that are descendants of a given ancestor.
-
:disabled Selector
FormSelects all elements that are disabled.
-
Element Selector (“element”)
BasicSelects all elements with the given tag name.
-
:empty Selector
Content FilterSelect all elements that have no children (including text nodes).
-
:enabled Selector
FormSelects all elements that are enabled.
-
:eq() Selector
Basic Filter, jQuery ExtensionsSelect the element at index
n
within the matched set. -
:even Selector
Basic Filter, jQuery ExtensionsSelects even elements, zero-indexed. See also odd.
-
:file Selector
Deprecated, Form, jQuery ExtensionsSelects all elements of type file.
-
:first-child Selector
Child FilterSelects all elements that are the first child of their parent.
-
:first Selector
Basic Filter, jQuery ExtensionsSelects the first matched element.
-
:focus selector
Basic Filter, FormSelects element if it is currently focused.
-
:gt() Selector
Basic Filter, jQuery ExtensionsSelect all elements at an index greater than
index
within the matched set. -
Has Attribute Selector [name]
AttributeSelects elements that have the specified attribute, with any value.
-
:has() Selector
Content Filter, jQuery ExtensionsSelects elements which contain at least one element that matches the specified selector.
-
:header Selector
Basic Filter, jQuery ExtensionsSelects all elements that are headers, like h1, h2, h3 and so on.
-
:hidden Selector
jQuery Extensions, Visibility FilterSelects all elements that are hidden.
-
ID Selector (“#id”)
BasicSelects a single element with the given id attribute.
-
:image Selector
Deprecated, Form, jQuery ExtensionsSelects all elements of type image.
-
:input Selector
Deprecated, Form, jQuery ExtensionsSelects all input, textarea, select and button elements.
-
:last-child Selector
Child FilterSelects all elements that are the last child of their parent.
-
:last Selector
Basic Filter, jQuery ExtensionsSelects the last matched element.
-
:lt() Selector
Basic Filter, jQuery ExtensionsSelect all elements at an index less than
index
within the matched set. -
Multiple Attribute Selector [name="value"][name2="value2"]
AttributeMatches elements that match all of the specified attribute filters.
-
Multiple Selector (“selector1, selector2, selectorN”)
BasicSelects the combined results of all the specified selectors.
-
Next Adjacent Selector (“prev + next”)
HierarchySelects all next elements matching "next" that are immediately preceded by a sibling "prev".
-
Next Siblings Selector (“prev ~ siblings”)
HierarchySelects all sibling elements that follow after the "prev" element, have the same parent, and match the filtering "siblings" selector.
-
:not() Selector
Basic FilterSelects all elements that do not match the given selector.
-
:nth-child() Selector
Child FilterSelects all elements that are the nth-child of their parent.
-
:odd Selector
Basic Filter, jQuery ExtensionsSelects odd elements, zero-indexed. See also even.
-
:only-child Selector
Child FilterSelects all elements that are the only child of their parent.
-
:parent Selector
Content Filter, jQuery ExtensionsSelect all elements that are the parent of another element, including text nodes.
-
:password Selector
Deprecated, Form, jQuery ExtensionsSelects all elements of type password.
-
:radio Selector
Deprecated, Form, jQuery ExtensionsSelects all elements of type radio.
-
:reset Selector
Deprecated, Form, jQuery ExtensionsSelects all elements of type reset.
-
:selected Selector
Form, jQuery ExtensionsSelects all elements that are selected.
-
:submit Selector
Deprecated, Form, jQuery ExtensionsSelects all elements of type submit.
-
:text Selector
Deprecated, Form, jQuery ExtensionsSelects all elements of type text.
-
:visible Selector
jQuery Extensions, Visibility FilterSelects all elements that are visible.
jQuery API
-
Keyboard navigation now available! Use up, down, tab, shift+tab, shift+upArrow and enter to navigate.
Browse the jQuery API
© 2012 The jQuery Foundation
Sponsored by Media Temple and others.