Pass element itself into action event handler - Javascript DOM Event

Javascript examples for DOM Event:event function

Description

Pass element itself into action event handler

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);
    }//from   w  w  w  .j  a  v a 2s  .c o m

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

Related Tutorials