Vanilla Js Ready() Function - What Is `document.documentelement.doscroll`?
I know similar questions have been asked here before, but I can't find any that asks or answers this specific question. I want an as simple as possible pure JavaScript ready functi
Solution 1:
It looks like doScroll is an IE thing. The readyState check is useful though, since the DOMContentLoaded event won't fire if it's already occurred. So, if you don't need IE support, I'd say you are fine removing the doScroll check, leaving you with:
if (document.readyState === "complete") {
// Document already fully loaded
ready();
} else {
// Add event listener for DOMContentLoaded (fires when document is fully loaded)
document.addEventListener("DOMContentLoaded", ready);
}
function ready() {
// Handler here
}
Post a Comment for "Vanilla Js Ready() Function - What Is `document.documentelement.doscroll`?"