When I want to prevent other event handlers from executing after certain event is fired I can do one of those (jQuery examples, but this will work in JS in general):
#1 event.preventDefault()
$('a').click(function (e) {
// custom handling here
e.preventDefault();
});
#2 return false
$('a').click(function () {
// custom handling here
return false;
};
Is there any significant difference between those two methods of stopping event propagation?
For me returning false
in simpler, shorter and probably you are less likely to make a typo while writing that then executing a method when you have to remember about correct casing, parenthesis etc. I don't have to assign first parameter in callback as well if I don't plan to use it in my code. But maybe there are some reason why I should avoid doing it like this and use preventDefault
instead.