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

lionel.web

Member
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/
 

chrishirst

Well-Known Member
Staff member
'window' is the top level object that contains the 'document object', which contains the page elements.

Not understanding such basics is one of the problems with the way that so many people think that "jquery" is all that is ever needed.
 

lionel.web

Member
ok, sorry for posting this info to the forum.
There is nothing to do with understanding. Is just a clarification for these two.
I wont do it again!
Everyone in here, know everything!
No sharing info again!
 

chrishirst

Well-Known Member
Staff member
My comment wasn't a dig at you, it was simply a general gripe about the 'popular' idea that no one ever needs to learn the basics of a programming or script language, and they can just jump in with an additional layer of complexity of a "framework" and hope "it just works". I saw another example yesterday at a different forum where the person was using "Bootstrap CSS" but did not know enough basic CSS to figure out why some radio buttons were truncating the caption text if it was too long for the container. Very few seem to grasp the idea that knowing the basics means not waiting several hours for somebody else to spoon feed an answer.

It's a bit like them hoping to solve simultaneous equations before learning the "times tables".
 

mobiouk

New Member
$(document).ready()
The ready() method makes a function available after loading the document. Whatever code you write inside the $( document ).ready() method will run once the page DOM is ready to execute JavaScript code.

$(window).load()
The code which gets included inside $( window ).on( "load", function() { ... }) runs only once the entire page is ready (not only DOM).
Note: The load() method is deprecated in jQuery version 1.8. It was completely removed it in version 3.0. To see if it's working, add the jQuery version for CDN before 3.0.
 

MeganCopeland

New Member
Understanding the basics of programming languages/scripts is crucial for effective problem solving and reducing reliance on outside help. Investing time in learning the fundamentals will empower individuals to solve problems independently. Or you can also go directly to apktome to find and download the best design or programming software for free and free of charge.
 
Top