Create <img> element and set image src - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Create <img> element and set image src

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 w  ww .j a  v a  2 s . c o m
    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