Cofey
Cofey

Reputation: 11404

How to ignore click() if an element has a certain class in jQuery?

I know this should be easy stuff, but for some reason the click event is still firing for the element that has a "selected" class.

Can anyone spot the problem with this line?

h.find("li a").not("li a.selected").click(function () {

Upvotes: 2

Views: 723

Answers (2)

daryl
daryl

Reputation: 15197

$(function() {
    $('div:not[.someclass]').click(function() {
        // do stuff
    });
});

Upvotes: 3

Phil
Phil

Reputation: 164766

Use

.not('.selected')

The not() filter applies to the current element

Upvotes: 5

Related Questions