Add image to image container - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Add image to image container

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <title>  Mehdi</title> 
   </head> 
   <body translate="no"> 
      <div id="image-container"></div> 
      <script>
function addImage(data) {/* w ww .  jav a  2 s .  com*/
    let imageElement = new Image();
    imageElement.src = data;
    console.log(imageElement);
    let imageContainer = document.getElementById('image-container');
    imageContainer.appendChild(imageElement);
}
addImage('https://dummyimage.com/100x100/ddd/000');
    
      </script>  
   </body>
</html>

Related Tutorials