Basic Selectors

All
*

selects all elements

ec 1.0+

everything (all elements including head, body, etc)

$('*')

everything that's an image (see :image)

$('*:image')

everything that's a child of #test

$('#test').find('*')
Class
.class

matches all elements with the given class name

ec 1.0+

all elements with .myClass applied

$('.myClass')

all elements with both .classA and .classB applied

$('.classA.classB')

all h2 elements with myClass applied

$('h2.myClass')
Element
element

selects all elements with the given tag

ec 1.0+

all div elements

$('div')

all list item elements

$('li')
Id
#id

selects a single element with the given id

e 1.0+

the element with an id of myDiv

$('#myDiv')

the element with an id of myID.entry[1] (note use of escape chars)

$('#myID\\.entry\\[1\\]')
Multiple
selector [,...selector]

selects the combined results of the given selectors

ec 1.0+

all div and span elements and all p elements with myClass applied

$('div,span,p.myClass')

Hierarchy Selectors

Child
parent > child

selects all direct child elements specified by child of elements specified by parent

ec 1.0+

all direct child li elements of any ul element with topnav class applied

$('ul.topnav > li')
Descendant
ancestor descendant

selects all elements that are descendants of a given ancestor

ec 1.0+

all input elements belonging to any form element (child input, grandchild input, etc)

$('form input')
Next Adjacent
prev + next

selects all next elements matching next that are immediately preceded by a sibling prev

ec 1.0+

all input elements immediately preceded by a label element (and sharing the same parent)

$('label + input')
Next Siblings
prev ~ siblings

selects all sibling elements that follow after the prev element, have the same parent and match the filtering siblings selector

ec 1.0+

all div elements following the element with id 'prev' (and sharing the same parent)

$('#prev ~ div')

Basic Filters

Animated
selector :animated

selects all elements that are in the progress of an animation at the time the selector is run

ec 1.2+

all divs that are currently being animated

$('div:animated')
Index
selector :eq( index )

selects the element at index within the matched set

e 1.0+

the third td element (in the entire document)

$('td:eq(2)')

the second li belonging to any ul with class 'nav' applied

$('ul.nav li:eq(1)')
First
selector :first

selects the first matched element

e 1.0+

the first tr element (in relation to parent)

$('tr:first')
Focus
selector :focus

selects element if it is currently focused

e 1.6+

the input element that currently has focus (if any)

$('input:focus')

if the element with id 'myInput' currently has focus

$('#myInput').is(':focus')
Greater Than Index
selector :gt( index )

selects all elements at an index greater than index within the matched set (contrasts with :lt)

ec 1.0+

all td elements from the 5th (element 4 due to 0 based indexing) onwards

$('td:gt(4)')
Header
selector :header

selects all elements that are headers, like h1, h2, h3 and so on

ec 1.2+

all headers in document

$(':header')
Langauge
:lang(language)

selects all elements that have a given language tag

ec 1.9+

all divs in document for en-us language

$('div:lang(en-us)')

all divs in document for en languages (e.g. en-us, en-gb, etc)

$('div:lang(en)')
Last
selector :last

selects the last matched element

e 1.0+

the last tr element from all tr elements found

$('tr:last')
Less Than Index
selector :lt( index )

selects all elements at an index less than index within the matched set (contrasts with :gt)

ec 1.0+

all td elements up to and including the 4th (element 3 due to 0 based indexing)

$('td:lt(4)')
Not
selector :not( selector )

selects all elements that do not match the given selector

ec 1.0+

all input elements that are not checked

$('input:not(:checked)')

all input elements that are not checked

$('input').not(':checked')
Odd Index
selector :odd

selects odd elements (contrasts with :even)

ec 1.0+

the 2nd, 4th, 6th etc tr elements

$('tr:odd')
Root
:root

selects the root of the document (the html element)

ec 1.9+

the html element

$(':root')

Content Filters

Contains
selector :contains( text )

selects all elements that contain the specified text

ec 1.1.4+

all divs that contain the text 'foo' somewhere in their content

$('div:contains("foo")')
Empty
selector :empty

selects all elements that have no children (including text nodes) (inverse of :parent)

ec 1.0+

all td elements that have no content or child items

$('td:empty')
Has
selector :has( selector )

selects elements which contain at least one element that matches the specified selector

ec 1.1.4+

all div tags that have a p element anywhere among its descendants

$('div:has(p)')
Parent
selector :parent

selects all elements that are the parent of another element, including text nodes (contrasts with :empty)

ec 1.0+

the parent elements of all found td elements

$('td:parent')

Attribute Filters

Attribute Has
selector [name]

selects elements that have the specified attribute, with any value

ec 1.0+

all divs that have an id attribute (regardless of value)

$('div[id]')
Attribute Equals
selector [name=value]

selects elements that have the specified attribute with a value matching a given string

ec 1.0+

all input elements that have a name attribute of 'foo'

$('input[name="foo"]')
Attribute Starts With
selector [name^=value]

selects elements that have the specified attribute with a value ending beginning exactly with a given string

ec 1.0+

all input elements that have a name attribute beginning with 'news' (e.g. 'newsletter', 'news' but not 'old news')

$('input[name^="news"]')
Attribute Ends With
selector [name$=value]

selects elements that have the specified attribute with a value ending exactly with a given string

ec 1.0+

all input elements that have a name attribute ending in 'letter' (e.g. 'letter', 'jobletter' but not 'letter post')

$('input[name$="letter"]')
Attribute Contains
selector [name*=value]

selects elements that have the specified attribute with a value containing the given substring

ec 1.0+

all input elements that have a name attribute containing 'man' (e.g. 'man-news', 'milkman', 'renewal')

$('input[name*="man"]')
Attribute Contains Word
selector [name~=value]

selects elements that have the specified attribute with a value containing a given word, delimited by spaces

ec 1.0+

all input elements that have a name attribute containing the word 'man' (e.g. 'man', 'milk man' but not 'manual')

$('input[name~="man"]')
Attribute Prefix
selector [name|=value]

selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-)

ec 1.0+

all a elements that have a hreflang attribute of 'en' or 'en-xxx' (where xxx can be anything)

$('a[hreflang|="en"]')
Attribute Not Equals
selector [name!=value]

selects elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value

ec 1.0+

all input elements that do not have a name attribute or do have a name attribute but not with a value of 'newsletter'

$('input[name!="newsletter"]')

Child Filters

Last Child
selector :last-child

selects all elements that are the last child of their parent

ec 1.1.4+

the last span in each matched div

$('div span:last-child')
Only Child
selector :only-child

selects all elements that are the only child of their parent

ec 1.1.4+

the button elements which are the only-child of any div

$('div button:only-child')

Visibility Filters

Form Selectors

Button
selector :button

selects all button elements and elements of type button

ec 1.0+

all button elements

$(':button')
Checkbox
selector :checkbox

selects all elements of type checkbox

ec 1.0+

all checkbox input elements within a form

$('form input:checkbox')
Checked
selector :checked

selects all elements that are checked

ec 1.0+

all checked checkbox/radio input elements within a form

$('form input:checked')
File
selector :file

selects all elements of type file

ec 1.0+

all file input elements

$('input:file')
Input
selector :input

selects all input, textarea, select and button elements

ec 1.0+

all input elements

$(':input')
Selected
selector :selected

selects all elements that are selected

ec 1.0+

the currently selected option element for each select form element

$('select option:selected')
Text
selector :text

selects all elements of type text

ec 1.0+

all text input elements

$('input:text')