Accessing the HTML DOM is very slow, compared to other JavaScript statements.

If you expect to access a DOM element several times, access it once, and use it as a local variable:

Example

var obj;
obj = document.getElementById("demo");
obj.innerHTML = "Hello";



Practice Excercise Practice now