You are on page 1of 2

JavaScript Cheat Sheet

by Dustin Allan (Pyro19D) via cheatography.com/581/cs/246/

Value Types Misc (cont) Event Handlers (cont)

Number Any numeric value isNaN() Returns true if something is not a onmouseup A mouse button is released

String Characters inside quote marks number. onmous​emo The mouse moves
setTim​eou Specify that am action should ve
Boolean True or False
t() occur on a particular schedule ondblclick A double click of a mouse button
Null Empty and meanin​gless
Math.floor Rounds a number down
onclick A single click (down and then
Object Any value associated with the object
Math.r​and Generaters a random number up) of a mouse button
Function Value returned by a function
om between 0 and 1
onreset A reset button is clicked on a
getEle​men​tsB​yTa​gName() form
Operators
getEle​men​tById() onkeydown Triggered when a key is pressed
x+y Adds x and y together
down
getEle​men​tsB​yCl​ass​Name()
(numeric)
onkeyup Triggered when a key is
elemen​t.i​n returns all the HTML between the
x+y Concat​inates x and y together
released
ne​rHTML opening and closing tags
(string)
elemen​t.n​o property, returns the number of onkeypress Triggered when a key is pressed
x-y Subtracts y from x
deType the node type and then released
x*y Multiplies x and y together
elemen​t.c​h A node list of child nodes that are
x/y Divides x by y Compar​isons
il​dNodes indexed numeri​cally, and appear
x%y Modulus: The remainder when x is in source order. x == Returns true if x and y are equal
divided by y elemen​t.c​h Returns the number of child y

x++, ++x Adds one to x il​dNo​des.l nodes of the element x === Returns true if x and y are identical
ength y
x--, --x Subtracts one from x

-x Reverses the sign on x x != y Returns true if x and y are not equal


Event Handlers
x !== Returns true if x and y are not identical
Assign​ments onabort The user aborted loading the y
page x>y Returns true if x is greater than y
x=y Sets x to the value of y
onblur The user left the object x >= Returns true if x is greater than or
x += y Same as x = x + y
onchange The user changed the object y equal to y
x -= y Same as x = x - y
onclick The user clicked an object x<y Returns true if x is less than y
x *= y Same as x = x * y
onerror The script encoun​tered an error x <= Returns true if x is less than or equal
x /= y Same as x = x / y
y to y
onfocus The user made an object active
x %= y Same as x = x % y
x && Returns true if both x and y are true
onload The object finished loading
y
Adding to an array onmous​eove The cursor moved over an
r object x || y Returns true if either x or y are true
.length Adds one value to the end of an
!x Returns true if x is false
onmouseout The cursor moved off an object
property array
onselect The user selected the contents
push() Adds one or more items to the end Remove item from an array
of an object
of an array
onsubmit The user submitted a form pop() Removes the last item from the array
unshift() Adds one or more items to the
onunload The user left the page shift() Removes the first item from the array
beginning of an array.

onmove The window is moved


Misc
onmous​edo A mouse button is pressed
parseInt() Takes a value and tries to convert wn down
it to an integer

By Dustin Allan (Pyro19D) Published 12th February, 2012. Sponsored by Readability-Score.com


cheatography.com/pyro19d/ Last updated 2nd June, 2014. Measure your website readability!
Page 1 of 2. https://readability-score.com
JavaScript Cheat Sheet
by Dustin Allan (Pyro19D) via cheatography.com/581/cs/246/

jQuery - Adding and removing content to a jQuery Filters


page
:even Selects every other element in a
.html() Retrieve or replaces the HTML and :odd group
inside the selection
:first and Selects the first or the last element
.text() Works like .html() but does not :last in a group
accept HTML tags
:not() to find elements that don't match a
.append() Adds HTML as the last child particular selctor type
element of the selected element
:has() finds elements that contain another
.prepend() Like .append(), but adds HTML selector
directly after the opening tag for :conta​ins Finds elements that contain
the selection () specific text
.before() Add HTML outside of a selection,
:hidden Locates elements that are hidden
just before the selected element
:visible Locates elements that are visible
.after() Add HTML outside of a selection,
just after the selected element

.remove() Completely remove a selected


element

.repla​ceW​i Completely replace selected


th() element

jQuery - other

.addClass Adds a specified class to an


element

.remov​eC Removes a specified class from an


lass element

.toggl​eCl​a Add a class if it doesn't already


ss() 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​eAt Completely removes an attribute


tr() from a tag.

.each() To loop through selection of


elements with your own
anonymous function.

By Dustin Allan (Pyro19D) Published 12th February, 2012. Sponsored by Readability-Score.com


cheatography.com/pyro19d/ Last updated 2nd June, 2014. Measure your website readability!
Page 2 of 2. https://readability-score.com

You might also like