5

我在下面有一些 div 标签:

<div class="magazine"></div>
<div class="newsletter"></div> // I need to take this div
<div class="may-moon"></div>

如果我需要类以“ ma ”开头的 div,我会使用$('div[class^="ma"]'),但相反的是什么?谢谢。

4

3 回答 3

14

相反的是使用jQuery :not()

$('div:not([class^="ma"])')
于 2013-06-27T01:34:11.793 回答
3

您可以像这样使用否定过滤功能“ not$('div').not('[class^="ma"]'),或者像这样使用否定选择器“ :not ”:($('div:not([class^="ma"])')正如Karl-André Gagnon所指出的)

于 2013-06-27T01:36:51.963 回答
0

您需要为此使用:not() Selector。因为在 jquery[^=]中不存在完全相反的选择器。*

:not() Selector - Selects all elements that do not match the given selector.

查看更多关于 Jquery 选择器的信息

存在相反的选择器!-

Attribute Not Equal Selector [name!="value"] - Select elements that either don’t have the specified attribute, or do have the specified attribute but not with a certain value.

但是使用这个!选择器,你需要提供类的全名。

$('div[class!="magazine"][class!="may-moon"]')  

尝试这个

于 2013-07-22T05:34:53.903 回答