JQuery: the difference between $(document).ready and $(window).load?
Two different events that could change your approach to coding with the help of jQuery.
$(document).ready — code will start its execution right after the DOM will be ready (except for the pictures). The indicated code will be executed immediately after DOM will be ready without waiting for the complete loading of pictures. Call of $(document).ready multiple times will lead to the consecutive execution of calls one by one.
$(document).on(‘ready’, function(){ /*starts executing after the DOM will be ready (except for the pictures) */ //your code }); |
$(window).load — the code which is written inside such construction will start working only after all the DOM will be ready, including the pictures. Such call is the great choice if you want to work with pictures (the calculation of the pictures’ size, and etc). Such call, as well as the previous one, is a jQuery event. If there are pictures on your page, then you need to wait untill these pictures will be loaded, and after that, the code will be executed.
$(window).load(function() { /* Will start execution after all the DOM will be ready, including the pictures, iframe… */ }); |