Skip to content

Instantly share code, notes, and snippets.

@zachary
Created August 31, 2024 17:15
Show Gist options
  • Save zachary/6997b863e831b69f19f6000ad3858763 to your computer and use it in GitHub Desktop.
Save zachary/6997b863e831b69f19f6000ad3858763 to your computer and use it in GitHub Desktop.
//*** Document Methods ***
document.getElementById('id'); // Returns the element with the specified id
document.getElementsByTagName ('tag');
// Returns a live HTMLCollection of elements with the specified tag name
document.getElementsByClassName ('class');
// Returns a live HTMLCollection of elements with the specified class name
document.createElement('tag'); // Creates and returns a new element of the specified type
document.createTextNode( 'text'); // Creates a new text node with the specified text
document.setAttribute('attr', 'value');
// Sets the value of an attribute on the specified element
document.getAttribute('attr');
// Returns the value of the specified attribute on the element
document.removeAttribute('attr'); // Removes the specified attribute from the element
document.addEventListener ('event', function);
// Attaches an event handler to the specified element
document.removeEventListener ('event', function);
// Removes an event handler from the specified element
//
//*** Node Methods ***
node.appendChild(newNode); // Appends a Node as the last child of a specified parent Node
node.hasChildNodes; // Returns true if the specified Node has child nodes
node.firstChild; // Returns the first child of the specified Node
node.lastChild; // Returns the last child of the specified Node
node.insertBefore(newNode, existingNode); // Inserts newNode before an existing Node
node.removeChild (childNode); // Removes a child Node from the specified parent Node
node.replaceChild(newNode, oldNode); // Replaces a child Node with a new Node
//*** Events ***
element.onclick = function;
// Sets or returns the function to be executed when the element is clicked
element.onmouseover = function;
// Sets or returns the function to be executed when the mouse pointer moves over an element
element.onmouseout = function;
// Sets or returns the function to be executed when the mouse pointer leaves an element
element.onchange = function;
// Sets or returns the function to be executed when the value of an element changes
//*** Keyboard Events ***
document.onkeydown = function;
// Sets or returns the function to be executed when a key is pressed down
document.onkeypress = function;
// Sets or returns the function to be executed when a key is pressed
document. onkeyup = function;
// Sets or returns the function to be executed when a key is released
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment