Show Menu
Cheatography

jQuery Cheat Sheet (DRAFT) by

Cheat sheet for all jQuery users: Noob to Pro!

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Including jQuery

From Folder
<script src="sc­rip­ts/­jQu­ery.js­></­scr­ipt>
From Google
<script src="//­aja­x.g­oog­lea­pis.co­m/a­jax­/li­bs/­jqu­ery­/1.1­0.0­/j­que­ry.m­in.js­"­></­scr­ipt>

Executing When The Document Is Ready

Method One
$(docu­men­t).r­eady(handler)
Method Two
$(handler)
handler
functi­on(){ ... }
Example
$(func­tion(){ alert(­'Do­cument Loaded'); });

Altering CSS

Add Class
.addCl­ass­("className")
Remove Class
.remov­eCl­ass­("className")
Toggle Class
.toggl­eCl­ass­("className")
Getting a CSS value
var value = $("selector"­).c­ss(­"property")
Getting an array of CSS values
var values = $("selector"­).c­ss(­["prop1"­,"prop2", ... ]
Setting a CSS Value
#(selector"­).c­ss(­"property", value)
Setting multiple CSS Values
#(selector"­).c­ss({'property' : value; 'property2' : value; ... })
Setting CSS based on a function
#(selector"­).c­ss(­"property", functi­on(­ind­ex,­value){ code; return value;}))
Element width
.width(); .width(value), .width(function)
 

Selecting content

Syntax
$("selector")
Select All
$("*­")
Select Tag
$("tag")
Select Class
$(".class")
Select ID
$("#ID")
Selector Extensions
:button, :checked, :even, :checkbox, :disabled, :enabled, :visible, :empty, :file, :first­-child, :first­-of­-type, :first, :last-­child, :last, :last-­of-­type, :focus, :hidden, :header, :image, :input, :lang, :odd, :only-­of-­type, :only-­child, :parent, :password, :radio, :reset, :root, :selected, :submit, :target, :text
Functional Selectors
:conta­ins('text'), :eq(2), :has( tag), :lt(n), :not(tag), :nth-c­hil­d(n), :nth-l­ast­-ch­ild(n), :nth-o­f-t­ype(n), :nth-l­ast­-of­-ty­pe(n)