开发者

jQuery: correct syntax for ':not()'

开发者 https://www.devze.com 2022-12-24 07:04 出处:网络
I\'m trying to filter a list of elements via \':not()\', and jQuery seems to be igno开发者_StackOverflow中文版ring my filter.

I'm trying to filter a list of elements via ':not()', and jQuery seems to be igno开发者_StackOverflow中文版ring my filter.

here is the code:

myElements.filter(':not(.someclass)');

jquery still selects all of myElements...


myElements = myElements.filter(":not(.someClass)");
myElements.hide();

or:

myElements = myElements.not(".someClass");
myElements.hide();

You will actually need to assign the filtered collection to a variable to capture the modified (filtered) collection, otherwise you are effectively just referencing myElements in its initial state. If you don't want to do that, you can always use chaining, for example:

myElements.filter(":not(.someClass)")
          .hide();
0

精彩评论

暂无评论...
验证码 换一张
取 消