Sunday, November 26, 2017

Part 2 - Difference between Document ready and Window onload Events




$(Document).Ready() vs window.onload()

$(document).ready() is a jQuery event. This method gets called as soon as the DOM gets ready.
DOM means all the html tags i.e. anchor tag, table, div, paragraph etc..). 

Main points for $(document).ready():
  1. It will not wait for the images, frames etc. to be loaded.
  2. It is used to execute JavaScript when the DOM is completely loaded. 
  3. It is not used if you want to manipulate images. Use window.onload() instead.

The window load event gets fired, when the complete page is fully loaded, including all frames, objects and images. Therefore functions which concern images or other page contents should be placed in the load event.

# Example



No comments: