How do I get a DOM element into a Javascript variable?

One useful method is to use document.querySelector.

This takes a string argument which will accept the same format used by CSS Selectors and return a DOM element if one matches the selector.

Here are a couple of examples:

var Body = document.querySelector("body"); // get the body element var Div = document.querySelector(".APPdiv"); // get an element with the class APPdiv

Â