Tuesday, December 24, 2013

What is the difference between window.onload and document.ready ?
share|improve this question
add comment

8 Answers

up vote302down voteaccepted
The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded.
The onload event is a standard event in the DOM, while the ready event is specific to jQuery. The purpose of the ready event is that it should occur as early as possible after the document has loaded, so that code that adds funcionality to the elements in the page doesn't have to wait for all content to load.
share|improve this answer
34 
Note that the ready event is an extension defined by jQuery, whereas onload is built-in. –  Piskvor Sep 13 '10 at 7:43
13 
You're wrong, ready event is not specific to jQuery, it is the same as DOMContentLoadeddeveloper.mozilla.org/en/DOM/DOM_event_reference/… –  baptx May 19 '12 at 21:38
36 
@baptx: You're wrong. The ready event is specific to jQuery. It's using the DOMContentLoaded event if it's available in the browser, otherwise it emulates it. There is no exact equivalent in the DOM because theDOMContentLoaded event is not supported in all browsers. –  Guffa May 19 '12 at 21:45
8 
Ok but the same result exists with DOMContentLoaded, maybe you should have specified this –  baptxMay 19 '12 at 21:51 
19 
@baptx: I didn't think that it was releveant to the question, and I still don't. –  Guffa May 19 '12 at 22:07
show 1 more comment

No comments: