Home > Article > Web Front-end > Analysis of the difference between window.onload and $(document).ready()_javascript skills
The example in this article describes the difference between window.onload and $(document).ready(). Share it with everyone for your reference. The specific analysis is as follows:
window.onload is a function in Javascript, which means: wait for all content in the web page to be loaded (including images);
$(documetn).ready() can be executed after all the DOM structures in the web page have been drawn. There may be elements associated with the DOM that have not been loaded, so it is faster in comparison;
For example, let’s take a simple example:
window.onload=function(){ alert('I am No.1'); }; window.onload=function(){ alert('I am No.2'); }
According to the above meaning, the result can only output "I am No.2"
Replacewith:
$(document).ready(function(){ alert('I am No.1'); }); $(document).ready(function(){ alert('I am No.2'); });
Result output I am No.1 ,I am No.2
I hope this article will be helpful to everyone’s JavaScript programming design.