0% found this document useful (0 votes)
323 views

Javascript Cheat Sheet

The document provides a cheat sheet on JavaScript and DOM manipulation. It includes common JavaScript events, DOM node and element methods, XMLHttpRequest methods and properties, and how to use JavaScript in HTML documents either through external files or inline. Key DOM manipulation methods covered are getElementById, getElementsByTagName, createElement, and addEventListener. Common events include onclick, onmouseover, onsubmit, and onload.

Uploaded by

a
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
323 views

Javascript Cheat Sheet

The document provides a cheat sheet on JavaScript and DOM manipulation. It includes common JavaScript events, DOM node and element methods, XMLHttpRequest methods and properties, and how to use JavaScript in HTML documents either through external files or inline. Key DOM manipulation methods covered are getElementById, getElementsByTagName, createElement, and addEventListener. Common events include onclick, onmouseover, onsubmit, and onload.

Uploaded by

a
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

T

T SHEE
A
Page 1 of 2
CHE Javascript
R IPT learntoprogram .tv
A SC
V
JA node.
appendChild(node) Append node as a child node.
Cheat Sheet removeChild(node) Remove child node node.
hasChildNodes() Returns true of the node has child
JavaScript in HTML
nodes.
<script type="text/javascript" Use external JavaScript childNodes Returns a NodeList of an element’s
src="javascript.js"></script> file javascript.js. The child nodes.
external file is loaded parentNode Returns the parent node as a Node
between <script> and </ object.
script>. insertBefore(newNode, Inserts newNode as a child node
<script type="text/javascript"> Inline JavaScript within the existingNode) before existingNode.
<!-- // JavaScript goes here --> HTML document.
</script> DOM Events

Mouse
Document Object Model (DOM) Manipulation
onclick User clicks on an element.
document. onmouseover Mouse pointer is moved over an element.
getElementById(elementID) Returns the element with id onmouseout Mouse pointer is moved off of an element.
elementID.
getElementsByTagName(tagName) Returns NodeList of elements Keyboard
with tag tagName. onkeydown A key is pressed down.
createElement(elementType) Create an element of the onkeyup A key is released.
specified type.
onkeypress User presses a key.
createTextNode(text) Create a text node with the
specified text. Form
createAttribute(attribute) Create an attribute of the
specified name. onchange The content of a form element has changed.
addEventListener(event, Attach an event handler of onfocus A form element gets focus.
function, useCapture) event to the document that onblur A form element loses focus.
runs function.
oninput An element gets user input.
T
T SHEE
A
Page 2 of 2
CHE
R IPT learntoprogram .tv
A SC
V
JA
onsubmit The form is submitted.
XMLHttpRequest Methods
Frame
abort() Cancel current request.
onload When an object has loaded. getAllResponseHeaders() Return all header information.
onresize When the document view is resized. getResponseHeader(header) Return specific header
onscroll When the page is being scrolled. information.
onerror When there has been an error loading an open(method, URL, async) Specify the type of request
external file. method, the request URL
URL, and whether it is handled
onpageshow A user has navigated to a webpage, after the
asynchronously or not.
onload event.
send(string) Sends the request, uses string
XML only for POST requests.
setRequestHeader(header, Adds a label/value pair of header
XMLHttpRequest value) and value to the request header.
var request = new XMLHttpRequest(); IE 7+, Firefox, Chrome,
XMLHttpRequest Properties
Safari, Opera
var request = new IE 5, IE 6 onreadystatechange Stores a function to be called
ActiveXObject("Microsoft.XMLHTTP"); when the readyState changes.
readyState The status of the
XMLHttpRequest readyState XMLHttpRequest.
0 Uninitiated responseText Returns response data as a
1 Loading string.
2 Loaded responseXML Returns response data as XML
3 Interactive status Returns the status-number.
4 Complete statusText Returns the status-text.

You might also like