PDA

View Full Version : Do u know the difference between jquery $(document).ready and $(window).load ???



marios.frag
12-17-2015, 08:54 PM
I thought, that there is no difference between these two. That both work and do stuff,
when the page has loaded. WRONG!!!
$(document).ready work when the DOM is ready.
That means that can be executed even when the pictures have NOT been loaded, cause the DOM is ready (the structure of the page and its elements)
But, when you need to do something, when EVERYTHING has loaded,
comes the $(window).load.
I found it out, when i needed to pass a javascript variable at the start of the page, and do something with that. I made it with $(document).ready and $(window).load

I found also this relative article. Check it out!
https://4loc.wordpress.com/2009/04/28/documentready-vs-windowload/

Akshay_M
01-24-2023, 09:42 AM
The key difference between $(document). ready() and $(window). load() event is that the code included inside onload function will run once the entire page(images, iframes, stylesheets,etc) are loaded whereas the $(document). ready() event fires before all images,iframes etc.