sij
sij

Reputation: 1347

bind event to all anchor tags except data-rel= back

I am working on a hybrid application using jQuery Mobile. The issue is I want to handle clicks to all anchor tags present in the application except data-rel back buttons.

Consider this code:

<a data-rel="back">leave me</a>

I cannot just select all a elements like so:

$("a").click(function(event) {
    alert("whooi handled all anchors")
}

Anyone have a suggestion on how to achieve this?

Upvotes: 2

Views: 465

Answers (1)

Jonas G. Drange
Jonas G. Drange

Reputation: 8845

What about using the Not Selector:

$('a:not([data-rel=back])')

You could also use the Attribute Not Equal Selector:

$('a[data-rel!=back]')

Does this work for you?

Upvotes: 4

Related Questions