We have several time seen Script wrapped in either $(document).ready function or $(window).load function but you might not be cleared about what they both does and how they are different from each other?
$(document).ready
$(document).ready function is very commonly used and you might also used this several time so why does we use it?
The reason of using it is to prevent our JavaScript to get executed before the HTML of the page gets loaded in other words by using $(document).ready our script will run after the HTML gets loaded.
$(window).load function
$(window).load function is also used sometimes now the question arises that why do we use this if we already have $(document).ready function ?
the reason of using it is $(window).load function allow our script to get executed when the page to be fully loaded along with inner frames, images etc in other words using $(window).load our script will run after the HTML inner frames and images etc gets loaded.
Now we have seen that $(document).ready function gets executed before $(window).load function so it we have two script on in $(document).ready function and another in $(window).load function the script in $(document).ready function will be executed first the reason of this is very simple script in $(document).ready will fire when HTML of the page gets loaded while the script in $(window).load will fire when HTML inner frames and images etc of the page gets loaded.
Stay tuned for the PHP Magento, WordPress,JavaScript and Magento2 latest tutorial and updates, Hope you enjoyed reading, if you need the professional Magento Development / PHP we can help you, just Click on the Link and send me your requirements.
Please Like the Post on Facebook or Google+.