Javier Garcia
Javier Garcia

Reputation: 41

How to know if an h1 element is loaded?

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

Answers (1)

Quentin
Quentin

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

Related Questions