Reputation: 3801
Is there a way in jQuery to call non specific elements with a certain attribute? I know you can search for a div for example with a set attribute.
$('div[data-snap-ignore="true"]');
But I have various elements that have the attribute data-snap-ignore that are not always divs, they can be sections, uls, buttons, all sorts really. However the following doesn't work.
$('[data-snap-ignore="true"]');
Upvotes: 1
Views: 141
Reputation: 5992
you could also use filter()
$('*').filter(function(){return $(this).data('myAttr') == true ;});
Or just: $('[data-myAttr]')
Or
$(':data').each(function(){ // your condition });; // All elements with data
$(':not(:data)').each(function{}()); // All elements without data
Upvotes: 0
Reputation: 106375
If you're looking for elements just having an attribute (without any specific value to target), drop the value part:
$('[data-snap-ignore]');
Otherwise (if you're targeting elements with data-snap-ignore
set to true
) it should work fine with the code given - no asterisk's required.
Upvotes: 0