Sometimes, we want to check if DOM is ready without a framework with JavaScript.
In this article, we’ll look at how to check if DOM is ready without a framework with JavaScript.
How to check if DOM is ready without a framework with JavaScript?
To check if DOM is ready without a framework with JavaScript, we can listen for the DOMContentLoaded
event.
For instance, we write
document.addEventListener("DOMContentLoaded", (event) => {
console.log("DOM fully loaded and parsed");
});
to listen for the DOMContentLoaded
event with addEventListener
.
We call it with a callback that runs when the DOM is fully loaded.
Conclusion
To check if DOM is ready without a framework with JavaScript, we can listen for the DOMContentLoaded
event.