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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.