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. onmousemo The mouse moves
setTimeou 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 meaningless
Math.floor Rounds a number down
onclick A single click (down and then
Object Any value associated with the object
Math.rand 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
getElementsByTagName() form
Operators
getElementById() onkeydown Triggered when a key is pressed
x+y Adds x and y together
down
getElementsByClassName()
(numeric)
onkeyup Triggered when a key is
element.in returns all the HTML between the
x+y Concatinates x and y together
released
nerHTML opening and closing tags
(string)
element.no 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
element.ch A node list of child nodes that are
x/y Divides x by y Comparisons
ildNodes indexed numerically, 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 element.ch Returns the number of child y

x++, ++x Adds one to x ildNodes.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
Assignments 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 encountered 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 onmouseove 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
onmousedo 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 :contains 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

.replaceWi Completely replace selected


th() element

jQuery - other

.addClass Adds a specified class to an


element

.removeC Removes a specified class from an


lass element

.toggleCla 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.

.removeAt 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