ドキュメント

API/1.3/Selectors

From jQuery JavaScript Library

(Redirected from Selectors)
Jump to: navigation, search

NameType
Basics:
NameType
#idReturns: Array<Element>
Matches a single element with the given id attribute.
elementReturns: Array<Element(s)>
Matches all elements with the given tag name.
.classReturns: Array<Element(s)>
Matches all elements with the given class.
.class.classReturns: Array<Element(s)>
Matches all elements with the given classes.
*Returns: Array<Element(s)>
Matches all elements.
selector1, selector2, selectorNReturns: Array<Element(s)>
Matches the combined results of all the specified selectors.
Hierarchy:
NameType
ancestor descendantReturns: Array<Element(s)>
Matches a descendant element specified by "descendant" of elements specified by "ancestor".
parent > childReturns: Array<Element(s)>
Matches all child elements specified by "child" of elements specified by "parent".
prev + nextReturns: Array<Element(s)>
Matches all next elements specified by "next" that are next to elements specified by "prev".
prev ~ siblingsReturns: Array<Element(s)>
Matches all sibling elements after the "prev" element that match the filtering "siblings" selector.
Basic Filters:
NameType
:firstReturns: Array<Element>
Matches the first selected element.
:lastReturns: Array<Element>
Matches the last selected element.
:not(selector)Returns: Array<Element(s)>
Filters out all elements matching the given selector.
:evenReturns: Array<Element(s)>
Matches even elements, zero-indexed. See also odd
:oddReturns: Array<Element(s)>
Matches odd elements, zero-indexed. See also even.
:eq(index)Returns: Array<Element>
Matches a single element by its index.
:gt(index)Returns: Array<Element(s)>
Matches all elements with an index above the given one.
:lt(index)Returns: Array<Element(s)>
Matches all elements with an index below the given one.
:headerReturns: Array<Element(s)>
Matches all elements that are headers, like h1, h2, h3 and so on.
:animatedReturns: Array<Element(s)>
Matches all elements that are currently being animated.
Content Filters:
NameType
:contains(text)Returns: Array<Element(s)>
Matches elements which contain the given text.
:emptyReturns: Array<Element(s)>
Matches all elements that have no children (including text nodes).
:has(selector)Returns: Array<Element(s)>
Matches elements which contain at least one element that matches the specified selector.
:parentReturns: Array<Element(s)>
Matches all elements that are parents - they have child elements, including text.
Visibility Filters:
NameType
:hiddenReturns: Array<Element(s)>
Matches all elements that are hidden.
:visibleReturns: Array<Element(s)>
Matches all elements that are visible.
Attribute Filters:Note: In jQuery 1.3 [@attr] style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the '@' symbol from your selectors in order to make them work again.
NameType
[attribute]Returns: Array<Element(s)>
Matches elements that have the specified attribute. Note the "@" before the attribute name was deprecated as of version 1.2.
[attribute=value]Returns: Array<Element(s)>
Matches elements that have the specified attribute with a certain value.
[attribute!=value]Returns: Array<Element(s)>
Matches elements that either don't have the specified attribute or do have the specified attribute but not with a certain value.
[attribute^=value]Returns: Array<Element(s)>
Matches elements that have the specified attribute and it starts with a certain value.
[attribute$=value]Returns: Array<Element(s)>
Matches elements that have the specified attribute and it ends with a certain value.
[attribute*=value]Returns: Array<Element(s)>
Matches elements that have the specified attribute and it contains a certain value.
[attributeFilter1][attributeFilter2][attributeFilterN]Returns: Array<Element(s)>
Matches elements that match all of the specified attribute filters.
Child Filters:
NameType
:nth-child(index/even/odd/equation)Returns: Array<Element(s)>
Matches all elements that are the nth-child of their parent or that are the parent's even or odd children.
:first-childReturns: Array<Element(s)>
Matches all elements that are the first child of their parent.
:last-childReturns: Array<Element(s)>
Matches all elements that are the last child of their parent.
:only-childReturns: Array<Element(s)>
Matches all elements that are the only child of their parent.
Forms:
NameType
:inputReturns: Array<Element(s)>
Matches all input, textarea, select and button elements.
:textReturns: Array<Element(s)>
Matches all elements of type text.
:passwordReturns: Array<Element(s)>
Matches all input elements of type password.
:radioReturns: Array<Element(s)>
Matches all input elements of type radio.
:checkboxReturns: Array<Element(s)>
Matches all input elements of type checkbox.
:submitReturns: Array<Element(s)>
Matches all input elements of type submit.
:imageReturns: Array<Element(s)>
Matches all input elements of type image.
:resetReturns: Array<Element(s)>
Matches all input elements of type reset.
:buttonReturns: Array<Element(s)>
Matches all button elements and input elements of type button.
:fileReturns: Array<Element(s)>
Matches all input elements of type file.
Form Filters:
NameType
:enabledReturns: Array<Element(s)>
Matches all elements that are enabled.
:disabledReturns: Array<Element(s)>
Matches all elements that are disabled.
:checkedReturns: Array<Element(s)>
Matches all elements that are checked. This includes checkboxes and radiobuttons.
:selectedReturns: Array<Element(s)>
Matches all elements that are selected.

Special characters in selectors

If you wish to use any of the meta-characters described above as a literal part of a name, you must escape the character with a backslash (\). Since Javascript uses the backslash for escape sequences in string literals, you must use two backslashes (\\) in string literals so that a single backslash will be put into the string 1.

Example:

"#foo\\:bar"
"#foo\\[bar\\]"
"#foo\\.bar"

The full list of characters that need to be escaped: #;&,.+*~':"!^$[]()=>|/