What is diffrence between $document.ready() and window.onload() ?

Programmers often use window.onload() in javascript and $document.ready() in jquery they assume that both the methods are same but no there is much difference between them.
Here is the difference that we cover today -

Documet.ready event

Jquery $document.ready function event executes a bit earlier than window.onload and called once the DOM(Document object model) is loaded on your page. DOM means all the html tags/script I.e.(anchor tag, table, div tag, paragraph tag etc..). It will not wait for the images, frames to get fully load. It means that it is the earliest stage in page load process.

It ensures that your dom is ready.(All needful resources are loaded completely) . Image are not considered under DOM ready.


below method is same as $(document).ready 



Window Onload event

It not exactly executed when DOM is loaded but it executes after all content including big images are loaded completely.

window.load is slightly slower than docuemt.ready because it waits for images and other resources to load completely.



Hope you have enjoyed the tutorial.


Thanks,

What is diffrence between $document.ready() and window.onload() ? What is diffrence between $document.ready() and window.onload() ? Reviewed by CodiBucket on 10:02 Rating: 5

No comments:

Facebook

Powered by Blogger.