Site Owners Forums - Webmaster Forums

Site Owners Forums - Webmaster Forums (http://siteownersforums.com/index.php)
-   Javascript (http://siteownersforums.com/forumdisplay.php?f=24)
-   -   Do u know the difference between jquery $(document).ready and $(window).load ??? (http://siteownersforums.com/showthread.php?t=162481)

george.web13 12-17-2015 12:20 PM

Do u know the difference between jquery $(document).ready and $(window).load ???
 
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/2...vs-windowload/

techvalens 01-19-2016 12:03 AM

difference between jquery $(document).ready and $(window).load
 
document.ready is a jQuery event, it runs when the DOM is ready, e.g. all elements are there to be found/used, but not necessarily all the content.
window.onload fires later (or at the same time in the worst/failing cases) when images and such are loaded. So, if you're using image dimensions for example, you often want to use this instead.


All times are GMT -7. The time now is 02:08 PM.


Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.