title: How to know if document has loaded
body: <p>I have a piece of JS code which needs to determine <strong>if DOM has loaded</strong>. I know there are several ways of executing JS code when DOM has loaded like:</p>
  
  <pre><code>$(document).ready(function() { ... }); // Jquery version
  
  document.body.onload = function() { ... } // Vanila JS way
  </code></pre>
  
  <p>I am looking for some method which looks like</p>
  
  <pre><code>function isDOMLoaded() {
      // Do something to check if DOM is loaded or not
      // return true/false depending upon logic
  }
  </code></pre>
  
  <p><strong>PS: Update (Post Answer Accept)</strong>
  I happen to see jquery also use the same approach to check if DOM has loaded. Take a look at the <a href="https://github.com/jquery/jquery/blob/eee2eaf1d7a189d99106423a4206c224ebd5b848/speed/jquery-basis.js" rel="nofollow">Implementation of jquery.ready() here</a></p>
  
  <pre><code>bindReady: function() {
      if ( readyBound ) {
          return;
      }
  
      readyBound = true;
  
      // Catch cases where $(document).ready() is called after the
      // browser event has already occurred.
      if ( document.readyState === "complete" ) {
          return jQuery.ready();
      }
  
      ...
  </code></pre>