jQuery, REAL :not operator equivalent?
this code line select all the children inputs inside any div who his class name is not "id" and "quantity" ::
$("div.item > div:not(.id,.quantity) > :input").live("keydown",function(event) {});
what is the code line to do the opposite?, something like ::
开发者_Python百科$("div.item > div:filter(.id,.quantity) > :input").live("keydown",function(event) {});
( of course :filter
is not a valid jQuery selector )
I don't know if I would recommend this, but you can use :not
twice:
$("div.item > div:not(:not(.id,.quantity)) > :input")
http://jsfiddle.net/6aW2B/
A better way is to create your own :is
selector
$.expr[':'].is = function(elem, index, match){
return $(elem).is(match[3]);
};
$("div.item > div:is(.id,.quantity) > :input")
http://jsfiddle.net/8Uny2/
I presume you are thinking of an "or" concept. Unfortunately, this doesn't really exist in jQuery/CSS selection. You need to do an "or" for the whole selection:
$('div.item > div.id > :input, div.item > div.quantity > :input')
If you are not using live
, the easiest way to do this is with DOM traversal:
$('div.item').children('div.id, div.quantity').children(':input')
Since you are using live
, the first example is probably the simplest technique.
精彩评论