JQuery Cheat Sheet

Basic use of jquery

jquery

Selectors

$(‘ *’ );
$(‘ ele­ment’ );
$(‘ . cl­ass’ );
$(‘ #ID’ );
$(‘ sel­ector1, selector2, select­orN’ );

DOM

. append()
. prepend()
. appen­dTo()
. prepe­ndTo()
. after()
. before()
. inser­tAf­ter()
. inser­tBe­fore()
. next()
. prev()
. data()
. attr(­’ at­tri­but­eNa­me’ ­, ’ a­tri­bute’ )
. remov­eProp()
prop()
. empty()
. remove()
. remov­eAttr()
. first()
. last()
. child­ren()
. find()
. html()
. text();
. val()
. end()
. css(‘ ­sty­leN­ame­’ ,’ ­style’ )
. addCl­ass()
. remov­eCl­ass()
toggle­Class()
. eq()
. end()
not()
var object = $. exte­nd({}, object1, object2);

Anim­ations and Effects

. slideUp()
. slide­Down()
. width­(‘ 0px’ )
. heigh­t(‘ ­0px’ )
. fadeO­ut(ms)
. fadeI­n(ms)
. hide(ms)
. show(ms)
. fadeT­oggle()
. slide­Tog­gle()
. toggl­e(‘ ­fas­t, s­low­’ ,ms)
. finish()
. stop()
. queue()
clearQ­ueue()
. dequeue()
. anima­te(­{‘ r­egl­a: c­ss’ ­}, m­s, f­unc­tio­n(){});

Event List

Browser Events
. resize()
. scroll()
Document Loading
. holdR­eady()
ready()
Event Handler Attach­ment
. on()
. bind()
form events
. blur()
. change()
. focus()
. select()
. submit()
Keyboard Events
. keydown()
. keypr­ess()
. keyup()
Mouse Events
. click()
. dblcl­ick()
focusin()
focusout()
. hover­(ha­ndl­erI­n, H­and­lerOut)
. hover­(ha­ndl­erI­nOut)
. mouse­down()
. mouse­enter()
. mouse­leave()
. mouse­move()
. mouse­out()
. mouse­over()
. mouseup()

basic syntax

$(‘ sel­ector’ )
. metho­dOne()
. metho­dTwo()
. metho­dN();

encaps­ulated function

(funct­ion(){})();

Event Object

e. curr­ent­Target
e. data
e. isDe­fau­ltP­rev­ented()
e. name­space
e. isIm­med­iat­ePr­opa­gat­ion­Sto­pped()
e. isPr­opa­gat­ion­Sto­pped()
e. pageX
e. pageY
e. prev­ent­Def­ault()
e. rela­ted­Target
e. result
e. stop­Imm­edi­ate­Pro­pag­ation()
e. stop­Pro­pag­ation()
e. target
e. time­Stamp
e. type
e. which

Event Handler

$(‘ sel­ect­or’ ­). e­ven­t(f­unc­tio­nName);
$(‘ sel­ect­or’ ­). e­ven­t(f­unc­tio­n(){});
$(‘ sel­ect­or’ ­). o­n(‘ ­eve­nt’ ­, fu­nct­ion­Name);
$(‘ sel­ect­or’ ­)on­(‘ e­ven­t’ ,­fun­cti­onN­ame­(){});
$bind(­’ ev­ent­’ ,f­unc­tion);
$(this)

AJAX

2

========

Jquery Bruce Cheat Sheet

jquery

Basic Selectors

*
All Elements (including head)
#ID
Element of specified ID
. classname
Elements of classname
tagname
Elements of tagname
a[href]
Anchor with href attribute
a[href­=’ v­alue’ ]
Anchor with href = ‘ value’
a[href­|=’ ­value’ ]
Anchor with href = ‘ value’
or
href starting with ‘ value-‘
a[href­^=’ ­value’ ]
Anchor with href beginning with ‘ value’
a[href­! =’ ­value’ ]
Anchor with href not equal to value
a[href­$=’ ­value’ ]
Anchor with href ending with ‘ value’
a[href­*=’ ­value’ ]
Anchor with href containing ‘ value’
a[href­~=’ ­value’ ]
Anchor with href = ‘ value’
or
href containing complete word ‘ value’
a[C1][C2]
Anchor with attributes satisfying criteria C1 and C2
s1s2
Elements satisfying
selector1 and selector2
s1, s2
Elements satisfying
selector1 or selector2
s1> s2
Elements satisfying
selector2
and
direct child of selector1
s1 s2
Elements satisfying
selector2
and
descen­dants of selector1
s1+s2
Elements satisfying
selector2
and
next immediate sibiling of selector1
s1~s2
Elements satisfying
selector2
and
next sibiling of selector1

Form Filters

: button
< bu­tto­n>
< input type = submit, reset or button>
: checkbox
: checked
checked or selected state
: selected
selected option of < se­lec­t>
: disabled
: enabled
: file
< input type=” f­ile­” >
: focus
: image
< intput type=” i­mag­e” >
: input
< in­put>
< select>
< textarea>
< button>
: password
< input type=” p­ass­wor­d” >
: radio
: reset
: submit
: text
< input type=” t­ext­” >

Attributes and Properties

$(A). a­ttr­(name)
get specified attribute value (in string) for first element in $(A)
$(A). attr(name, value|Function)
$(A). attr({name: value|Function, etc}}
set specified attribute for all elements in $(A)
$(A). r­emo­veA­ttr­(name)
$(A). p­rop­(name)
get specified attribute value for first element in $(A)
$(A). prop(name, value|Function)
$(A). attr({name: value|Function, etc}}
$(A). r­emo­veP­rop­(name)
$(A). d­ata­(na­me, ­value)
Store name=value pair in jQuery memory cache
if name is my-love, it is stored as myLove
$(A). d­ata­([n­ame])
Get name value from jQuery Cache else data-name attribute
$(A). removeData([name])
$. removeData(js elemen­t, [­name])
$. hasD­ata(js element)
Check if element has any associated data in jqeury cache

Position Filters

: first
: last
: eq(n)
nth element (0-based index)
: lt(n)
: gt(n)
elements before­/after nth index
: even
: odd
elements at even /odd index
: first-child
: last-child
nth-child(n)
nth-child(even|odd)
nth-child(Xn+Y)
nth child (1-based index)
nth-last-child(n)
nth-last-child(even|odd)
nth-last-child(Xn+Y)
nth child, starting from the last
nth-of-type(n)
nth-of-type(even|odd)
nth-of-type(Xn+Y)
nth-last-of-type(n)
nth-last-of-type(even|odd)
nth-last-of-type(Xn+Y)
: only-­child
elements with no sibilings
: only-­of-type
elements with no sibilings of same type

Content Filters

: conta­ins­(text)
elements containing text
: empty
: has(s­ele­ctor)
elements containing at least one selector
: parent
elements with at least one child node

Other Filters

: animated
elements currently under animated control
: header
< h1> through < h6>
: visible
: hidden
: lang(­lan­guage)
: not(s­ele­ctor)
: root
element which is root of the document
: target
element targeted by the document’ s URI’ s identifier