Different between onload() and document.ready() in jquery
Loading
Different between onload() and document.ready() in jquery
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Brahma Prakash ShuklaPosted Oct 30, 2022, 12:40 PM
The onload executes a block of code after the page is completely loaded while $(document). ready(function) executes a block of code once the DOM is ready.
Rajanikant HawaldarPosted Oct 30, 2022, 10:42 AM
the load event (a.k.a "onload") on the window and/or body element will fire once all the content of the page has been loaded -- this includes all images, scripts, etc... everything.
In contrast, jquery's $(document).ready(...) function will use a browser-specific mechanism to ensure that your handler is called as soon as possible after the HTML/XML dom is loaded and accessible. This is the earliest point in the page load process where you can safely run script that intends to access elements in the page's html dom. This point arrives earlier (often much earlier) than the final load event, because of the additional time required to load secondary resources (like images, and such).