Window.onload event and $(document).ready()
I am learning jQuery. Could someone please explain what the difference between the window.onload
event and $(document).ready()
in jQuery is?
Regar开发者_StackOverflow社区ds, JN
The difference between window.onload and $(document).ready() is explained in the jQuery tutorial
I quote:
The first thing that most Javascript programmers end up doing is adding some code to their program, similar to this:
window.onload = function(){ alert("welcome"); }
Inside of which is the code that you want to run right when the page is loaded. Problematically, however, the Javascript code isn't run until all images are finished downloading (this includes banner ads). The reason for using window.onload in the first place is that the HTML 'document' isn't finished loading yet, when you first try to run your code. To circumvent both problems, jQuery has a simple statement that checks the document and waits until it's ready to be manipulated, known as the ready event.
精彩评论