document.addEventListener(
"DOMContentLoaded",
function() {
// your code here
},
false
);
or;
function docReady(fn) {
// see if DOM is already available
if (document.readyState === "complete" || document.readyState === "interactive") {
// call on next available tick
setTimeout(fn, 1);
} else {
document.addEventListener("DOMContentLoaded", fn);
}
}
console.dir(dom);