Handle <img> on load event action - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Handle <img> on load event action

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//from  www.jav  a 2 s .  c  om
    var myanim = new Image();
    myanim.src = 'http://www.java2s.com/style/download.png';
    myanim.onload = function() {
        document.getElementById('anim').src = myanim.src;
    }
    });

      </script> 
   </head> 
   <body> 
      <img id="anim" src="http://www.java2s.com/style/download.png">  
   </body>
</html>

Related Tutorials