Call preventDefault() method on event - Javascript DOM Event

Javascript examples for DOM Event:preventDefault

Description

Call preventDefault() method on event

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  ww w. j a  v a  2s .  c  o 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