or   Register or Register today to make and share your own cheat sheets! (Why Join?)

Cheatography Login

Join Us!

Not a Cheatographer? Register here!

Social Media

You can login to or register with Cheatography using your Facebook or Twitter account!

Why Join Cheatography?

Make and share cheat sheets!
Join a great community of Cheatographers and add your very own contributions.

Save your favourites!
Quick access to your most loved cheat sheets.

Fewer ads!
Members see no ads on the site.

Coming soon ...
Requests, ratings and more!

Why Join Cheatography?

Make and share cheat sheets!
Join a great community of Cheatographers and add your very own contributions.

Save your favourites!
Quick access to your most loved cheat sheets.

Fewer ads!
Members see no ads on the site.

Coming soon ...
Requests, ratings and more!

JavaScript Cheat Sheet by Pyro19D

1 Comment   |   Add a Comment   |   PDF Download   |   Find:

Value Types

Number Any numeric value
String Characters inside quote marks
Boolean True or False
Null Empty and meanin­gless
Object Any value associated with the object
Function Value returned by a function

Operators

x + y (numeric) Adds x and y together
x + y (string) Concat­inates x and y together
x - y Subtracts y from x
x * y Multiplies x and y together
x / y Divides x by y
x % y Modulus: The remainder when x is divided by y
x++, ++x Adds one to x
x--, --x Subtracts one from x
-x Reverses the sign on x

Assignments

x = y Sets x to the value of y
x += y Same as x = x + y
x -= y Same as x = x - y
x *= y Same as x = x * y
x /= y Same as x = x / y
x %= y Same as x = x % y

Adding to an array

.length property Adds one value to the end of an array
push() Adds one or more items to the end of an array
unshift() Adds one or more items to the beginning of an array.

Misc

parseInt() Takes a value and tries to convert it to an integer
isNaN() Returns true if something is not a number.
setTim­eout() Specify that am action should occur on a particular schedule
Math.floor Rounds a number down
Math.r­andom Generaters a random number between 0 and 1
getEle­men­tsB­yTa­gName()
getEle­men­tById()
getEle­men­tsB­yCl­ass­Name()
elemen­t.i­nne­rHTML returns all the HTML between the opening and closing tags
elemen­t.n­odeType property, returns the number of the node type
elemen­t.c­hil­dNodes A node list of child nodes that are indexed numeri­cally, and appear in source order.
elemen­t.c­hil­dNo­des.length Returns the number of child nodes of the element
 

Event Handlers

onabort The user aborted loading the page
onblur The user left the object
onchange The user changed the object
onclick The user clicked an object
onerror The script encoun­tered an error
onfocus The user made an object active
onload The object finished loading
onmous­eover The cursor moved over an object
onmouseout The cursor moved off an object
onselect The user selected the contents of an object
onsubmit The user submitted a form
onunload The user left the page
onmove The window is moved
onmous­edown A mouse button is pressed down
onmouseup A mouse button is released
onmous­emove The mouse moves
ondblclick A double click of a mouse button
onclick A single click (down and then up) of a mouse button
onreset A reset button is clicked on a form
onkeydown Triggered when a key is pressed down
onkeyup Triggered when a key is released
onkeypress Triggered when a key is pressed and then released

Comparisons

x == y Returns true if x and y are equal
x === y Returns true if x and y are identical
x != y Returns true if x and y are not equal
x !== y Returns true if x and y are not identical
x > y Returns true if x is greater than y
x >= y Returns true if x is greater than or equal to y
x < y Returns true if x is less than y
x <= y Returns true if x is less than or equal to y
x && y Returns true if both x and y are true
x || y Returns true if either x or y are true
!x Returns true if x is false

Remove item from an array

pop() Removes the last item from the array
shift() Removes the first item from the array
 

jQuery - Adding and removing content to a page

.html() Retrieve or replaces the HTML inside the selection
.text() Works like .html() but does not accept HTML tags
.append() Adds HTML as the last child element of the selected element
.prepend() Like .append(), but adds HTML directly after the opening tag for the selection
.before() Add HTML outside of a selection, just before the selected element
.after() Add HTML outside of a selection, just after the selected element
.remove() Completely remove a selected element
.repla­ceW­ith() Completely replace selected element

jQuery - other

.addClass Adds a specified class to an element
.remov­eClass Removes a specified class from an element
.toggl­eCl­ass() Add a class if it doesn't already exist, or remove the class if it does
.css() Lets you directly read or change CSS properties of an element
.attr() Reads a specified HTML attribute from a tag. Sets the specified HTML attribute if a second argument is passed.
.remov­eAttr() Completely removes an attribute from a tag.
.each() To loop through selection of elements with your own anonymous function.

jQuery Filters

:even and :odd Selects every other element in a group
:first and :last Selects the first or the last element in a group
:not() to find elements that don't match a particular selctor type
:has() finds elements that contain another selector
:conta­ins() Finds elements that contain specific text
:hidden Locates elements that are hidden
:visible Locates elements that are visible

Favourited by 33 Members:

GaBBBBB Pufahl sting2kx jagrock naesk Wbbourne Psyco21 desert_jay Rober1992 guslong fire9 zenweasel imjoshholloway rd5coding pneumatix sleeven kjhughes ernest The_Frail andshecodes2 pedromarban isalcedo manjuv.gmit tomlouie weevie asafge MrOggy85 TwEeD tbasallo oronm mambero tuuli Dranzz

Comments

el el, 11:46 24 Jan 13

you got a mistake there, length does not add a value to an array. :(

Add a Comment

Comment:

Contents

JavaScript

Column Content Comments Author Updated
- JavaScript Cheat Sheet Pyro19D 1 Apr 12
1 Value Types 0 Pyro19D 12 Feb 12
Operators 0 Pyro19D 12 Feb 12
Assignments 0 Pyro19D 12 Feb 12
Adding to an array 0 Pyro19D 20 Feb 12
Misc 0 Pyro19D 18 Mar 12
2 Event Handlers 0 Pyro19D 12 Mar 12
Comparisons 0 Pyro19D 12 Feb 12
Remove item from an array 0 Pyro19D 20 Feb 12
3 jQuery - Adding and removing content to a page 0 Pyro19D 1 Apr 12
jQuery - other 0 Pyro19D 1 Apr 12
jQuery Filters 0 Pyro19D 1 Apr 12