2

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!

2 Answers 2

9

Here is what you want

$(".product[data-product!='radio']")

or

$(".product:not([data-product='radio'])")

Hope this helps

Sign up to request clarification or add additional context in comments.

Comments

1

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"])')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.