Languages
[Edit]
EN

HTML - onload event attribute

0 points
Created by:
user4838
368

In this article, we would like to show you how to use onload event attribute in HTML.

Quick solution:

<img src="https://example.com/image.png" onload="myFunction()" />

 

Practical example

In this example, we create handleLoad() function and assign it to the HTML onload event attribute so it will be executed when the image is loaded successfully.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<body>
  <script>

    function handleLoad(image) {
      console.log('Image loaded successfully: (' + image.src + ').');
    }

  </script>
  <img src="/static/bucket/1574890428058-BZOQxN2D3p--image.png"
       alt="Image loading error." 
       onload="handleLoad(this)" />
</body>
</html>
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join