JQuery, REAL: not the equivalent of a statement?

this line of code selects all child inputs within any div whose name is not "id" and "quantity" ::

$("div.item > div:not(.id,.quantity) > :input").live("keydown",function(event) {}); 

what is a line of code to do the opposite? , sort of::

 $("div.item > div:filter(.id,.quantity) > :input").live("keydown",function(event) {}); 

(of course :filter not a valid jQuery selector)

+4
source share
2 answers

I don't know if I recommend this, but you can use :not twice:

 $("div.item > div:not(:not(.id,.quantity)) > :input") 

http://jsfiddle.net/6aW2B/

It’s best to create your own selector :is

 $.expr[':'].is = function(elem, index, match){ return $(elem).is(match[3]); }; $("div.item > div:is(.id,.quantity) > :input") 

http://jsfiddle.net/8Uny2/

+3
source

I assume you are thinking of an β€œor” concept. Unfortunately, this really does not exist in jQuery / CSS selection. You need to make an β€œor” for all choices:

 $('div.item > div.id > :input, div.item > div.quantity > :input') 

If you are not using live , the easiest way to do this is to bypass the DOM:

 $('div.item').children('div.id, div.quantity').children(':input') 

Since you are using live , the first example is probably the easiest method.

+3
source

All Articles