Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

HTML | DOM onload Event

  • Last Updated : 30 Jul, 2021

The DOM onload event in HTML occurs when an object has been loaded. The onload event is mostly used within the element, The <body>
The onload event can be used to check the browser type and browser version, and load the version of the web page based on the information. The onload event can also be used for cookies.
Supported tags 

  • <body>
  •  <frame>
  •  <iframe>
  •  <img>
  •  <input type=”image”>
  •  <link> 
  • <script>
  • , <style>


Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

  • In HTML: 
<element onload="myScript">
  • In JavaScript: 
object.onload = function(){myScript};
  • In JavaScript, using the addEventListener() method: 
object.addEventListener("load", myScript);

Example: using the addEventListener() method 


<!DOCTYPE html>
      HTML DOM onload Event
        <img src=
        <p id="pid"></p>
              "imgid").addEventListener("load", GFGFun);
            function GFGFun() {
                document.getElementById("pid").innerHTML =
                  "Image loaded";


Supported Browsers: The browsers supported by HTML DOM onload Event are listed below: 

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera


My Personal Notes arrow_drop_up
Recommended Articles
Page :