Question

When manipulating things as height of a div for instance, or various css rules, it's a good thing that the document is completely loaded. So why not always use (window).load instead of (document).ready when manipulating objects in the dom?

Was it helpful?

Solution 2

Because "document ready" is much earlier. It says that the DOM has been loaded and is ready for manipulation.

"window load", on the other hand, also includes images, videos and possibly flash elements - all elements which could potentially take a long time to load (especially Flash unless it has a proper preloader), and that you would have to wait for before your page does anything, even though there's no reason to.

OTHER TIPS

It certainly depends on your needs.

Suppose your site has a lot of images but you need certain events that need to be triggered as soon as the document is ready,Then using a $(window).load(//your events) would wait for all the images to load first and then trigger the events. In this case it would be preferable to use $(document).ready(//your events).

You can follow up this question here,

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

Because what you can do today you don't wait for tomorrow. Document ready fire after Dom ready where as window load wait for all the resources to download.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top