我在下面有一些 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"]')
,但相反的是什么?谢谢。
我在下面有一些 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"]')
,但相反的是什么?谢谢。
相反的是使用jQuery :not():
$('div:not([class^="ma"])')
您可以像这样使用否定过滤功能“ not ” $('div').not('[class^="ma"]')
,或者像这样使用否定选择器“ :not ”:($('div:not([class^="ma"])')
正如Karl-André Gagnon所指出的)
您需要为此使用:not() Selector
。因为在 jquery[^=]
中不存在完全相反的选择器。*
:not() Selector - Selects all elements that do not match the given selector.
存在相反的选择器!
-
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"]')