Pass event itself into the event handler function - Javascript DOM Event

Javascript examples for DOM Event:event function

Description

Pass event itself into the event handler function

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function onClick(e) {/*from   w ww  . j ava2  s .  co  m*/
    if (e){
         e.preventDefault();
    }
    console.log(e);
}

      </script> 
   </head> 
   <body> 
      <a href="#" onclick="onClick(event)">Works</a>
      <br>
      <br> 
      <a href="#" onclick="onClick()">Doesn't Work</a>  
   </body>
</html>

Related Tutorials