What is the difference between $(document).ready() and window.onload?
| $(document).ready() | window load |
|---|---|
| Runs when the HTML DOM is ready | Runs when everything is loaded (images, CSS, frames) |
| Faster | Slower |
| Can be used many times | window.onload = keeps only the last function (use $(window).on('load') for many) |
Use ready for most code, and load when you need the size of images. See Document Ready Function.
Learn more about the similar topics:
| Tutorials |
|---|
| jQuery Introduction |
| jQuery Get Started |
| jQuery Syntax |
| jQuery Document Ready Function |
| jQuery noConflict() Method |
| jQuery vs Vanilla JavaScript |
| jQuery 4 and Upgrading from jQuery 3 |
| Exercises & Assignments |
|---|
| No Content Found. |