I want to prevent links from opening pages. So I have written this :
$("a").click(function(e) {
e.preventDefault()
}
which is great! But this blocks my other event :
$(".toolbar a").click(function(e) {
...action...
}
Sure I can add my action to the first event with some test, but is there an elegant way to prevent only href event from executing?
EDIT
In fact it works, sorry. See @raina77ow fiddle working here: http://jsfiddle.net/HeFS6/
Best Answer
Use
return false
instead. You can see the code below working here.As pointed by @raina77ow with this article, using
return false
is the same as callingevent.preventDefault()
and alsoevent.stopPropagation()
. As I had troubles withoutreturn 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.