What is the difference between $(document).ready() and $(window).load()?

The $(document).ready() starts when the page has been loaded.

The $(window).load() starts later, when the window has been loaded, this means the page including the images, frames and objects.

In case your code is about images, you best choose for the later one. When your code has nothing to do with images/frames/objects you best choose the first one.

you can test it with the following code:

$(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");
Post comment