document.addEventListener("DOMContentLoaded", function() { // code });
window.addEventListener('DOMContentLoaded', (event) => { console.log('DOM fully loaded and parsed'); });
<!-- The DOMContentLoaded event will fire as soon as the DOM hierarchy has been fully constructed (Doesn't wait for images, CSS, advertisements to load), the load event will do it when all the images and sub-frames have finished loading. -->