Reporting Which Button Was Clicked when Clicked by display its id - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Reporting Which Button Was Clicked when Clicked by display its id

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script>
function myFunction(e){//from  ww w.  ja  va 2 s.co  m
  console.log(e.id);
}

      </script> 
      <input type="button" id="1" class="buttonID" value="answer" onClick="myFunction(this)"> 
      <input type="button" id="2" class="buttonID" value="answer" onClick="myFunction(this)"> 
      <input type="button" id="3" class="buttonID" value="answer" onClick="myFunction(this)">  
   </body>
</html>

Related Tutorials