- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Page Load Events
JavaScript Events
JavaScript Page Load Events
DOMContentLoadedandloadtell you when the page is ready to work with.
A script that runs too early cannot find the elements it needs.
These events say when it is safe to start.
Example
Example
javascript
document.addEventListener("DOMContentLoaded", function () {
console.log("the HTML is ready");
});
document.dispatchEvent(new Event("DOMContentLoaded"));