jquery document ready with pure js code example
Example 1: jQuery Dom ready equivalent in pure JavaScript
docReady(function() {
// DOM is loaded and ready for manipulation here
});
Example 2: jQuery Dom ready equivalent in pure JavaScript
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);
}
}