.Maui Blog

Pure JavaScript equivalent of jQuery’s $.ready()

Supported by all modern browser and IE9+.

var callback = function() {
    // Handler when the DOM is fully loaded
};

if (document.readyState === "complete" ||
    (document.readyState !== "loading" && !document.documentElement.doScroll)
) {
    callback();
} else {
    document.addEventListener("DOMContentLoaded", callback);
}

Example taken from this article.

Exit mobile version