Vanilla JavaScript: A yummy cheatsheet

for selectors, event listeners and creating HTML elements

1. Set up your DOM Selectors

Classic Selectors

document.getElementById(“login_form”); // Returns one itemdocument.getElementsByClassName("button-primary");  // Returns an HTML collection of items that satisfy the class namedocument.getElementsByTagName("h1"); // Returns an HTML collection of items that satisfy the tag name
  • return elements as a live collection…