Vic Vic - 4 years ago 210
Javascript Question

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.

Answer Source

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...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download