Michael
Michael

Reputation: 2046

How do I do an "or" statement with the jQuery :not() function?

So, I'm trying to figure out if this is possible or not. I have a .find(':input:not(button)') function in my code and I'm trying to exclude additional things besides the button. So I'm looking for a way to do this: .find(:input:not(button || otherthing)'). Is this possible? I know that syntax isn't correct as it's not working, but I'm hoping that some of you know how to do this. Thanks for your help.

Upvotes: 0

Views: 66

Answers (3)

RobertPitt
RobertPitt

Reputation: 57268

you can use the function instead of the filter, for example:

$(element).find('input').not('button').not('otherthing');

You can also do this which is much simpler:

    $(element).find('input:not(button, otherthing)');

Source: http://api.jquery.com/not-selector/

Upvotes: 2

tskuzzy
tskuzzy

Reputation: 36476

Let's do a little boolean algebra shall we?

~(A OR B) = ~A AND ~B

So this translates to

.find('input:not(button)').filter('input:not(otherthing)')

Upvotes: 0

user578895
user578895

Reputation:

:not(button):not(otherthing)

will definitely work. jQuery may also accept this syntax, but don't hold me to it:

:not(button,otherthing)

Upvotes: 0

Related Questions