Create an <img> element, assign src - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Create an <img> element, assign src

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <div id="destination"> 
         <!-- Destination Div --> 
      </div> 
      <script>
  // Creates Image
  var image = document.createElement("img");
  // Sets Image Attributes
  image.src = "http://www.java2s.com/style/download.png";
  image.width = "30";
  image.height = "30";
  // Adds Image to Body
  document.getElementById("destination").appendChild(image);
  
      </script>  
   </body>/*from   ww w. ja  v  a2s.  c o m*/
</html>

Related Tutorials