1.

In jQuery, what is the difference between the $(window).load and $(document).ready functions?

Answer»
$(window).load$(document).ready
$(window).load is an event that occurs when the DOM and another page's contents are fully loaded. This event occurs following the ready event. In most circumstances, the script may be run as soon as the DOM has finished loading.The ready() method is typically the ideal location to write JavaScript code

However, there may be times when you need to write scripts in the load() method. For instance, to determine the true width and height of a picture.


Once the DOM, CSS, pictures, and frames are entirely loaded, the $(window).load event is called. As a result, it is the optimal area to write jQuery code to determine the real picture size or to obtain information about anything.


When a function needs to be made available after the document has loaded, use the ready() method. Whatever code you include in the $(document).ready() method will be executed once the DOM of the page is prepared to run JavaScript code.



Discussion

No Comment Found