Reputation: 41
I have the code below to show an alert when a h1 element is loaded, but the alert is never shown, why?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<body>
<h1>Lorem ipsum</h1>
<script>
var a = document.getElementsByTagName('h1');
a[0].onload = function() { alert() };
</script>
</body>
</html>
Upvotes: 0
Views: 111
Reputation: 944083
Unlike img
and iframe
elements, an h1
element is not a means to reference an external resource.
There is no load event because there is nothing to load. You don't have to make an additional HTTP request to fetch Lorem ipsum
; it is baked into the HTML.
If the element exists, then it is as loaded as it is going to get.
Upvotes: 3