List of common jQuery selectors. I had compiled this list a while ago into a word document but do not remember the source now.
|
*
|
All
|
|
element
|
Element
|
|
.class
|
Class
|
|
#id
|
ID
|
|
[name]
|
Has Attribute
|
|
[name|="value"]
|
Contains Prefix (before hyphen (-))
|
|
[name*="value"]
|
Contains
|
|
[name~="value"]
|
Contains Word
|
|
[name^="value"]
|
Starts With
|
|
[name$="value"]
|
Ends With
|
|
[name="value"]
|
Equals
|
|
[name!="value"]
|
Not Equal
|
|
[name="v"][name2="v2"]
|
Multiple Attributes
|
|
:button
|
Button
|
|
:checkbox
|
Checkbox
|
|
:submit
|
Submit
|
|
:text
|
Text
|
|
:password
|
Password
|
|
:radio
|
Radio
|
|
:reset
|
Reset
|
|
:file
|
File
|
|
:image
|
Image
|
|
:input
|
input, textarea, select and button elements
|
|
:contains(text)
|
Elements that contain the specified text.
|
|
:eq(n)
|
Element at index n within the matched set.
|
|
:gt(n)
|
Elements at an index greater than n within the matched set.
|
|
:lt(n)
|
Elements at an index less than index within the matched set.
|
|
:has(selector)
|
Elements which contain at least one element that matches the specified selector.
|
|
:not(selector)
|
Elements that do not match the given selector.
|
|
:nth-child()
|
Elements that are the nth-child of their parent.
|
|
:empty
|
Elements that have no children (including text nodes).
|
|
:even
|
Even elements, zero-indexed.
|
|
:first
|
The first matched element.
|
|
:header
|
Elements that are headers, like h1, h2, h3 and so on.
|
|
:last
|
The last matched element.
|
|
:odd
|
Odd elements, zero-indexed.
|
|
:checked
|
Checked
|
|
:animated
|
Animated
|
|
:disabled
|
Disabled
|
|
:enabled
|
Enabled
|
|
:focus
|
Focused
|
|
:selected
|
Selected
|
|
:visible
|
Visible
|
|
:hidden
|
Hidden
|
|
parent > child
|
Direct child elements specified by "child" of elements specified by "parent".
|
|
ancestor descendant
|
Elements that are descendants of a given ancestor.
|
|
selector1, selector2, selectorN
|
Combined results of all the specified selectors.
|
|
prev + next
|
Next elements matching "next" that are immediately preceded by a sibling "prev".
|
|
prev ~ siblings
|
Sibling elements that follow after the "prev" element, have the same parent, and match the filtering "siblings" selector.
|
|
:first-child
|
Elements that are the first child of their parent.
|
|
:last-child
|
Elements that are the last child of their parent.
|
|
:only-child
|
Elements that are the only child of their parent.
|
|
:parent
|
Elements that are the parent of another element, including text nodes.
|
Hmm, maybe it would be good to have the methods listed with args too. This is what I look up the most.
This will be great to some other beginners, like me.
Yeah, as Ben said it is only jQuery "selectors" - which are basically CSS selectors with a few helpful additions.
Should probably be called 'jQuery Selector Cheat Sheet' as it only covers that topic. Useful though, thanks,
I know this will make a lot of people very happy - a jQuery cheat sheet has been requested for a long time! Good job :)
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.