Difference between body.onload() and document.ready() function
The body.onload() event will be called once the DOM and all associated resources like images got loaded. Basically, onload() will be called when the page has been fully loaded with entire images, iframes and stylesheets, etc.
For example, if our page contains a larger size image, so onload() event will wait till the image is fully loaded.
The document.ready() function will be executed as soon as the DOM is loaded. It will not wait for the resources like images, scripts, objects, iframes, etc to get loaded.
We can have multiple document.ready() function in our code but only one body.onload() is allowed.
Difference between body.onload and document.ready:
|onload() will be called only when everything gets loaded.||This function is called as soon as DOM is loaded.|
|It will wait till all resources like images, iframes, objects, scripts get loaded.||It will be called once DOM is loaded.|
|We can have only one body.onload() function.||We can have multiple documents.ready() function in our page.|