1
Reply

What is the difference between window.onload and onDocumentReady in JavaScript?

Atul Jain

Atul Jain

12y
3.1k
0
Reply

    window.onload- Code in this method get executed when DOM tree is ready. But fact is code in this method executed when DOM tree is ready and All the external resource are load like Images, Flash vidoe or quicktime video. Loading of the external resources deplay execution of the actual script when page get displayed.
    $(document).redy- Code in this method get executed once DOM tree loading is done. That means its not wait for the external resource get loaded. And run the javascript code which is in function.


    So if you use Windows.onload than end user have to wait to see expected behaviour till DOM tree and external resouce get loaded by the browser. Where as in case of $(document).redy script get exeucuted once Dom tree loaded by browser.