I found this example in a JavaScript book
// Checks to see if the DOM is ready for navigation
function isDOMReady() {
// If we already figured out that the page is ready, ignore
if (domReady.done) return false;
// Check to see if a number of functions and elements are
// able to be accessed
if (document && document.getElementsByTagName && document.getElementById && document.body) {
// If they're ready, we can stop checking
clearInterval(domReady.timer);
domReady.timer = null;
// Execute all the functions that were waiting
for (var i = 0; i < domReady.ready.length; i++)
domReady.ready[i]();
// Remember that we're now done
domReady.ready = null;
domReady.done = true;
}
}
// calling the domReady function
domReady(function () {
alert("The DOM is loaded!");
tag("h1")[0].style.border = "4px solid black";
});
Want to understand that what domReady.done, domReady.timer means?
domReady.doneis a flag that will be set to true as soon as the DOM is ready.domReady.timeris the reference / handle to an interval started withwindow.setIntervalso that it can be cleared withwindow.clearInterval()as soon as the DOM is ready because there is no need to check any longer.