return false vs preventDefault() - Javascript DOM Event

Javascript examples for DOM Event:preventDefault

Description

return false vs preventDefault()

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.4.2.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//  w  w  w . j av a2  s  . co m
$("a").click(function(e) {
    e.preventDefault();
});
$("div").click(function() {
    $(this).css("border", "1px solid red");
});
    });

      </script> 
 </head> 
 <body> 
  <div>
    Here is some text 
   <a href="www.google.com">Click!</a> 
  </div>  
 </body>
</html>

Related Tutorials