Reputation: 15
Below is my <script>
tag:
var2=document.querySelector('html')
var2.addEventListener('load',function(){alert('yo')});
why is onload
not working?
And this is not just with html
tag but with basically any selector.
Upvotes: 0
Views: 619
Reputation: 943517
Most elements don't load content (the obvious exceptions being <iframe>
and <img>
) so load events don't fire on them.
If you want to capture the page's load event, then you shouldn't bind to any element:
addEventListener("load", yourEventHandlerFunction);
Upvotes: 1