Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 935
Vic Avatar asked Jan 12 '23 22:01

Vic


1 Answers

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...
like image 115
Rory McCrossan Avatar answered Jan 17 '23 06:01

Rory McCrossan