Handle <img> click event and show its id - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Handle <img> click event and show its id

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <img id="img1" src="a.png" alt="" onclick="select(this.id)"> 
      <img id="img2" src="a.png" alt="" onclick="select(this.id)"> 
      <script>
    function select(id){
      console.log(id);
    }// w w w .j  a  va 2s .  co  m

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

Related Tutorials