My website has eventlisteners for various actions. I currently add these eventlisteners to my elements once the whole DOM has loaded, like this:
document.addEventListener('DOMContentLoaded', function() {
document.getElementById("someid").addEventListener("click", somefunction(); });
})
I’ve gotten feedback from some users with poor internet connexion that they have to wait sometimes up to a full minute for the whole page to load before the website to work properly..
Is there a way to add an eventlistener to an element the instant it loads on the page instead of waiting for the whole DOM to load? I’d rather not go back to using onclick=”” within the HTML like in the olden days.
By choice, I only use vanilla javascript.
Thanks in advance.