jQuery“没有属性”选择器?


142

我可以找到一个具有如下属性的div:

$('.funding-plan-container[data-timestamp]')

但是,如果我尝试查找不具有该属性的div,则会收到错误消息-我的代码是:

$('.funding-plan-container[!data-timestamp]')

jQuery中是否有“没有属性”选择器?

作为参考,这里的用例是没有动态添加任何没有timestamp属性的div,因此很有用。

谢谢!

Answers:



37

您可以使用.not():not()选择器过滤选择器。

$('.funding-plan-container:not([data-timestamp])').

要么

$('.funding-plan-container').not('[data-timestamp]') 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.