JavaScript 2025 · DOM and browser
Run code when the page is ready
Wait for the HTML to be parsed. Scripts with defer or type=module don't need this.
document.addEventListener("DOMContentLoaded", () => {
init();
});
Official JavaScript 2025 documentation