Though it seems window.onload and jQuery’s $(document).ready() events do the same , but they very much differ in their functioning.
JavaScript provides the load event for executing code when a page is rendered. The load event ("onload") on the window and/or body element will be called only after the DOM and associated resources like images get loaded. That is, the load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images and sub-frames have finished loading.
The handler passed to .ready() is guaranteed to be executed after the DOM is ready . With $(document).ready(), we can get our events to load or fire before the window loads. load event does not get triggered until all assets such as images have been completely received.
JavaScript provides the load event for executing code when a page is rendered. The load event ("onload") on the window and/or body element will be called only after the DOM and associated resources like images get loaded. That is, the load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images and sub-frames have finished loading.
The handler passed to .ready() is guaranteed to be executed after the DOM is ready . With $(document).ready(), we can get our events to load or fire before the window loads. load event does not get triggered until all assets such as images have been completely received.