Document ready và window load
View Discussion Improve Article Save Article View Discussion Improve Article Save Article 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. Example: HTML
Output: body onload 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. Example: HTML
Output: DOM is ready Difference between body.onload and document.ready:
|