I know the basic difference between these states but a weird problem was came in one of our project
jQuery(document).ready(function () {
console.log('Dom is ready');
jQuery(document).ready(function () {
console.log('Inner Dom ready');
});
});
Result :-
Dom is ready
Inner Dom ready
Now, Thats fine at any time, whenever I call document.ready()
, It executes its handler.
But if you look at this
jQuery(window).load(function () {
console.log('Window Loaded');
jQuery(window).load(function () {
console.log('Inner window load');
});
});
Result :-
Window Loaded
Why the inner window load never executes its handler, even though window is already loaded.
Thanks for your comments and answers but i am just curious to know how they work internally, I agree jQuery(window).load() event only fires once so there is no chance of any other load event handler to execute then why this rule is not applied to jQuery(document).ready(). Does it set some kind of flag or something and checks every time we call it.