window.onload vs $(document).ready()

Brad Johnson. January 18, 2017 Comments

The document.ready event occurs after the HTML document (document object) has been loaded.

The window.onload event occurs later when document is ready as well as all the resources is loaded like (images, iframes, js, css etc.).

$(document).ready(function() {
 // executes when HTML-Document is loaded and DOM is ready
 alert("document is ready");
});


$(window).load(function() {
 // executes when complete page is fully loaded, including all frames, objects and images
 alert("window is loaded");
});

 

  • js-dom