2

Possible Duplicate:
JavaScript: event.preventDefault() vs return false

What are the cases when return false does not do the same thing as e.preventDefault() ?

(Note I'm not talking about jQuery events.. but JavaScript events in general)

The only situation I can think of is a click event on a hyperlink (if you return false in the handler you will still be redirected to the website)

Note that if its not a click event but a mousedown event on the hyperlink return false works same as e.preventDefault().

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Name
  • 741
  • 1
  • 8
  • 8

1 Answers1

0

I believe that return false is equivalent to e.preventDefault(); and e.stopPropagation(); at the same time. However, I recommend that you use the functions and the return false for future and past browser compatibility:

$("#something").click(function(e){
    alert("Something was clicked");
    e.preventDefault();
    return false;
});

Ad@m

kirb
  • 2,033
  • 1
  • 18
  • 28