Prevent href from opening link but still execute other bind events Prevent href from opening link but still execute other bind events jquery jquery

Prevent href from opening link but still execute other bind events


Use return false instead. You can see the code below working here.

​$("a").click(function() {    return false;});$(".toolbar a").click(function() {    alert("Do something");});​

As pointed by @raina77ow with this article, using return false is the same as calling event.preventDefault() and also event.stopPropagation(). As I had troubles without return false on some codes in the past, I always suggest it.

But the most importante thing here is the bind order: your last bind will be your first executed code. So, take care about it and go.


In place of e.preventDefault(), have you tried return false? This should also prevent browser default behaviour.


There is no href event. That is what you'd end up with if prevent default on click. You should just use more specific selectors.