pass the id of an element that triggers an `onclick` event to the event handling function - Javascript DOM Event

Javascript examples for DOM Event:onclick

Description

pass the id of an element that triggers an `onclick` event to the event handling function

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <title>  mrmoje</title> 
      <style>

div{cursor:pointer}
div:hover{text-decoration:underline}


      </style> 
   </head> 
   <body translate="no"> 
      <div onclick="myHandler()" id="my element's id">
         Click Here//from   w  ww .  ja  v a 2  s  .  c  o  m
      </div> 
      <script>
      function myHandler(){
          console.log(myHandler.caller.arguments[0].target.id)
      }
    
      </script>  
   </body>
</html>

Related Tutorials