This might be a rookie question, but I have searched and tried a lot. What the is difference between window.onload
and $window.load
?
There are great answers about the difference between window.onload and document.ready and document.onload vs window.onload etc, but I have not found a resource or article that mentions both .onload
and .load
.
jQuery documentation says that .load is
"This method is a shortcut for .on( "load", handler )."
I tried putting both window.onload
and window.load
on the page and seeing which gets hit first or if they both get hit but they seem to interfere with each other.
(window).onload(function(){
alert("window onload - executes when the window's load event fires.");
}
$(document).ready(function(){
alert("document is ready - executes when HTML-Document is loaded and DOM is ready");
}
$(window).load(function(){
alert("window is loaded - executes when complete page is fully loaded, including all frames, objects and images");
}
What are the differences between them and why would you use one over the other?