Execute a script when the element is finished loading in HTML?

HTMLWeb DevelopmentFront End Technology

Use the onload attribute to execute a script when the element is finished loading.

Example

You can try to run the following code to implement onload attribute −

<!DOCTYPE html>
<html>
   <head>
      <script>
         function display() {
         alert("Welcome!");
         }
      </script>
   </head>
   <body onload = "display()">
      <h3>Welcome to the website.</h3>
      <p>We offer learning content.</p>
   </body>
</html>
raja
Published on 13-Mar-2018 12:46:39
Advertisements