Jquery Cheatsheet
Jquery Cheatsheet
Selects elements with specified attribute containing value as a substring Selects elements with specified attribute starting with value
All ('*')
Element ('element') ['<form formname="my one log">...</form>','<form formname="hog log dog">...</ ['<form formname="signin">...</form>','<form formname="newuser">...</form>']
form>']
Selects specified element $('[callsign]')
$('[callsign~="alpha"]')
$('div') ['<div callsign= "charlie">...</div>','<a callsign= "nocallsign">...</a>']
['<div callsign="alpha beta delta">...</div>','<h1 callsign="a alpha b">...</h1>']
['<div id= "first">...</div>','<div id= "second">...</div>'] Multiple Attribute ('[name="value"][name2="value2"')
Filters, which begin with colons (:), can be appended to regular selectors to filter out
Selects the last matched element Selects the child element of a parent matching the given index (1-index)
elements that don't match the filter.
$(':last')
For example, $(':animiated') will give you all animated on a page, while :nth-last-child()
$('form:animated') will give you animated elements within a form. ['<li id= "last">...</li>']
Selects the child element of parent matching the given index, starting from the
:lt()
:animated last (1-index)
Selects from matched elements with an index less than the given index (zero-
Selects elements that are currently being animated index)
:nth-last-of-type()
:eq() $(li:lt(3))
Selects the nth element of a type among siblings of same parent, starting from
Selects the element at the given index of the matched set (zero-index) last (1-index)
['<li id="one">...</li>', '<li id="two">...</li>', '<li id="three">...</li>']
$('li:eq(4)')
:not() :nth-of-type()
['<li id="five">...</li>']
Selects elements that do not match the given selector Selects the nth element of a type among siblings of same parent (1-index)
$('li:eq(0)')
$('input:not(:password)')
['<li id= "one">...</li>'] :only-child
['<input type="text">', '<input type="submit">']
:even Selects elements when they are only child of their parent
:odd
Selects elements with an even index in the matched set (zero-index) Selects elements with an odd index in the matched set (zero-index)
:only-of-type
$('li:even') $('li:even')
Selects elements when they have no siblings of same type
['<li id="one">...</li>', '<li id="three">...</li>', '<li id="five">...</li>'] ['<li id="two">...</li>', '<li id="four">...</li>', '<li id="six">...</li>']
:first :root
CONTENT FILTERS
Selects the element at the root of the document :contains()
Selects the first matched element
$(':root') Selects all elements that contain the specified text
$('li:first')
['<html>...</html>'] $(':contains("Pretty Printed")')
['<li id= "one">...</li>']
Selects element that is currently focused Selects the element targetted in URL (e.g. http://url.com/#home) :empty
m
:header Selects element that is the first child of parent
co
Selects elements that have at least one element of given selector
Selects elements that are headers (h1, h2, ...)
:first-of-type $('div:has(table)')
d.
$(':header')
nte
Selects first of element type that is a child of parent
i
pr
['<div><table>...</table></div>']
['<h1>...</h1>', '<h3>...</h3>']
ty
et
:last-child
r
:lang() $(':parent')
//p
Selects element that is the last child of parent
Selects elements with the given language. Selects elements that have at least one child element
:
:last-of-type
ttp
$(':lang(en-us)')
Selects last of element type that is a child of parent
$(:parent)
h
['<div lang="en-us">...</div>'] ['<table><tr>...<tr></table>','<div><h1>...</h1></div>']
jQUERY SELECTOR BASIC ATTRIBUTE HIERARCHY BASIC FILTERS CHILD FILTERS
:focus :text
m
Selects elements that are in focus Selects elements that are type text
$(':text') . co
$(':focus')
d
['<input type="text">']
nte
['<select>...</select>']
i
y pr
:image
t
ret
//p
Selects elements of type image
:
tp
$(':image')
['<input type="image">'] ht