1.

Explain the difference between window.onload and onDocumentReady.

Answer»

Both window.onload and onDocumentReady are used to perform operations when the web page has been loaded. However, there are differences in these in terms of EXECUTION.

window.onload is TRIGGERED when the DOM and all external resources like images and videos are loaded. Due to the loading of external resources, there is a delay in the execution of the actual script when the page is displayed. window.onload is not cross-browser compatible while using jQuery.  

On the other hand, the onDocumentReady method is triggered when the DOM has loaded, i.e it waits for the HTML elements to be loaded but not for multimedia content like images and videos. The DOM tree has been BUILT when the onDocumentReady event is triggered. THUS, any delays in the execution of the script are reduced. Moreover, it is compatible with all browsers.



Discussion

No Comment Found