Reputation: 3075
I have an attribute being applied to my dynamically created divs called data-product
. Is there a selector I can use to select all divs without a specific data-product
value? For instance, if one of the data-product values is "radio," is there a way I can select every div with a data-product value that does not equal radio?
<div data-product="radio" class="product"></div>
<div data-product="television" class="product"></div>
<div data-product="speakers" class="product"></div>
Thanks in advance!
Upvotes: 2
Views: 5876
Reputation: 724452
You can either use jQuery's proprietary attribute-not-equal selector:
$('div.product[data-product!="radio"]')
Or if you prefer a more standards-based selector (i.e. one that can be used in CSS), use :not()
with a regular attribute selector:
$('div.product:not([data-product="radio"])')
Upvotes: 1
Reputation: 4624
Here is what you want
$(".product[data-product!='radio']")
or
$(".product:not([data-product='radio'])")
Hope this helps
Upvotes: 9