[英]jQuery find elements without data attribute
How can I find all elements without a certain data-attribute? 如何在没有特定数据属性的情况下找到所有元素?
I've tried: 我试过了:
$list.find('li:not([data-stuff])');
But it doesn't work. 但它不起作用。
jQuery stores data
attributes in its cache, so you need to use filter: jQuery将
data
属性存储在其缓存中,因此您需要使用过滤器:
var $li = $list.filter(function() {
return $(this).data('stuff') != undefined;
});
// do something with $li...
I think what you're looking for is: 我想你要找的是:
$list.find('li').not('li[data-stuff]').addClass('foo');
The addClass()
is just there as a placeholder. addClass()
就在那里作为占位符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.