Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery "Does not have attribute" selector?

I can find a div that has an attribute like so:

$('.funding-plan-container[data-timestamp]')

But if I try to find a div that does not have that attribute, I get an error - my code is:

$('.funding-plan-container[!data-timestamp]')

Is there a "does not have attribute" selector in jQuery?

For reference, the use case here is that any div that does not have a timestamp attribute was not added dynamically, and hence is useful.

Thanks!

like image 446
Harry Avatar asked Oct 04 '22 22:10

Harry


1 Answers

Use the :not() selector.

$('.funding-plan-container:not([data-timestamp])')

This, by the way, is a valid Selectors API selector, so it isn't specific to jQuery. It'll work with querySelectorAll() and in your CSS (given browser support).

like image 244
I Hate Lazy Avatar answered Oct 06 '22 11:10

I Hate Lazy