Alex Rivera | Logout

Prevent href from opening link but still execute other bind events

Asked 2012-09-06T11:37:45.850
30

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/

Edit
Report

1 Answer

0

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.

answered 2012-09-06T11:41:34.363

Your Answer