Skip to content

$(document).ready() equivalent in JavaScript

In jQuery $(document).ready() function is used to execute a code block before the page contents are loaded. This can be achieved using the plain JavaScript like:

 var loader = setInterval(function () {
            if(document.readyState !== "complete") return;
            clearInterval(loader);
            alert("Document loaded!");
         }, 300);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.