Create button displays image and set CSS display - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Create button displays image and set CSS display

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <img src="" style="display:none" id="img" width="200"> 
      <button class="popup" onclick="display('http://www.java2s.com/style/download.png')">Show Image</button> 
      <script>
  function display(imagepath){
     var img = document.getElementById("img");
     img.src = imagepath;
     img.style.display = 'block';
  }//  ww w  .j av a2  s. co m

      </script>  
   </body>
</html>

Related Tutorials