4

I want to filter multiple values from an event in jQuery.

At the moment I have:

.filter(":not(.element)")

How would I go about adding more things to filter? I've tried:

.filter(":not(.element, .another, .etc)")

and

.filter(":not(.element)").filter(":not(.another)").filter(":not(.etc)")

and

.filter(":not(.element),:not(.another),:not(.etc)")

With no luck. What do I need to do?

Thanks.

EDIT: Thanks for the answers - I've find another solution to my problem that avoids having to do what I've asked in the question, but evidently I wasn't doing something properly in my code since the solutions posted work. I will mark an answer as correct, many thanks.

2
  • It does work - jsfiddle.net/DKbPK Commented May 14, 2012 at 10:14
  • 1
    All your samples should work, theres something else wrong with your code. Commented May 14, 2012 at 10:18

3 Answers 3

9

It is working, you just need to separate each element using a comma (,) in the :not() selector.

You can check the example here: http://jsfiddle.net/LVUMs/

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

Comments

4

Looks like it is working. http://jsbin.com/uyayot/edit#javascript,html

I tried:

$('div').not('#div2,#div4').each ( function () {
    alert ( $(this).attr ('id' ) );
  });

Comments

2

You can use not() by chaining it. Like this

$('yourElement').not(':even').not('.SomeMore').not('.fewmore')

1 Comment

Even though it would work - it doesn't explain why other OP's attempts failed

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.