2

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 () {

2 Answers 2

5

Use

.not('.selected')

The not() filter applies to the current element

Sign up to request clarification or add additional context in comments.

Comments

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

6 Comments

According to the manual, the .not() method is preferred over the :not selector
@Phil Yeah I'm sure it is. Although this is the method I prefer myself, I even posted this after having saw you posted as I feel its good to get a broader insight of how one thing can be achieved. Regards
Interesting that they would specifically suggest .not(), :not should have better performance.
@phil, No they don't, the .not() is 2 separate calls. It first gets the broader set then filters it. I found a speed test, .not is considerably slower, I'd have to find it again though.
found it jsperf.com/jquery-css3-not-vs-not bigger numbers are better. On small sets of data I'm sure it's negligible. I have had to search over a very large table and found avoiding chaining gave me a reasonable performance increase.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.