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

DOM Selector

getElementById()
querySelector()
getElementsByClassName()
getElementsByTagName()
querySelectorAll()
parentNode
previsouSibling
nextSibling
firstChild
lastChild

DOM Node Types

Document
Element
Text
Attribute
Whitespace
in browsers other than IE, whitespace is treated as text node

DOM Text Node

nodeValue
Called on text node

DOM Element Node

innerHTML
textContent
createElement()
createTextNode()
appendChild()
removeChild()
create functions will not put the node into DOM tree. Need to use append­Child() to add the newly created element in DOM.

DOM Attribute Node

className
id
hasAttribute()
getAttribute()
setAttribute()
removeAttribute()
These are called on element node

Document Object

write()
encode­URI­Com­pon­ent­(str)

IE5~8

event.t­arget
event.s­rc­Element
func(e)
window.event
addEve­ntL­ist­ener()
attach­Event()
event.p­re­ven­tDe­fault()
event.r­et­urn­Val­ue=­false
event.s­to­pPr­opa­gat­ion()
event.c­an­cel­Bub­ble­=false
 

UI Event

load
unload
error
resize
scroll

Mouse Event

click
dblclick
mousedown
mouseup
mousemove
mouseover
mouseout

Focus Event

focus / focusin
element gains focus
blur / focusout
element lose focus

Keyboard Event

keydown
keyup
keypress

Form Event

input
change
select, check box, radio button
submit
reset
cut
copy
paste
select

Mutation Event

DOMSub­tre­eMo­dified
DOMNod­eIn­serted
DOMNod­eRe­moved
DOMNod­eIn­ser­ted­Int­oDo­cument
DOMNod­eRe­mov­edF­rom­Doc­ument
 

Event Binding

Event handler attribute:
<... onclic­k="f­unc­()">  // bad practice


Event handler
el.onc­lic­k=f­unc()


Event listener
el.add­Eve­ntL­ist­ene­r('­click', func, [boolean])

el,add­Eve­ntL­ist­ene­r('­click', function() { myFunc(0) }, [boolean])


Support for older IE (5-8)
if(el.a­dd­Eve­ntL­ist­ener) {

el.add­Eve­ntL­ist­ener()

} else {

    el.att­ach­Eve­nt(­'cl­ick', myFunc())}