Get event.target from event handler - Javascript DOM Event

Javascript examples for DOM Event:target

Description

Get event.target from event handler

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <div id="a" onclick="doSomething(event);">
          div "a" 
         <div id="b">
             div "b" 
         </div> 
         <div id="c">
             div "c" 
         </div> 
      </div> 
      <script type="text/javascript">
function doSomething(e) {/*from  www  .j  a  v  a 2s .c  o m*/
    if (e.target.id !== "b") {
        console.log(e.target.id);
    }
}

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

Related Tutorials