What is main difference between the $(document).ready () and window.onload()?
The main differences are the $(document).ready() event called when your HTML document is loaded and DOM is ready and it's don't wait for your content and images etc. fully loaded but window.onload()(<body onload="func();">) event is wait for your content and images etc. fully loaded.
The main differences are the $(document).ready() event called when your HTML document is loaded and DOM is ready and it's don't wait for your content and images etc. fully loaded but window.onload()(<body onload="func();">) event is wait for your content and images etc. fully loaded.
The $(document).ready() function is called only one time when your page is loading not for partial page rendering in that case you need to use pageLoad() function.
Document
Ready function:-
We
can call more than one document.ready()
function in single page.
The document.ready() function is called when DOM is not fully loaded that means rest of
images, css or other 3rd party reference on page.
It
will not wait for the images, css or other 3rd party to get loaded.
Body
Onload function:-
The
body.onload() function, we can have only one body.onload() function.
The
body.onload() function is called when everything fully loaded on the page like
DOM, images and css or other 3rd party reference on page.
It
will wait for the images, css or other 3rd party to get loaded.
The ready
and load events:
1.
$(document).on('ready', handler)
2.
$(document).on('load', handler)
The ready
and load functions:
1.
$(document).ready(handler)
2.
$(document).load(handler)
I Hope it is helpful to you! Thank you!