jQuery "Does not have attribute" selector?

JavascriptJquery

Javascript Problem Overview


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!

Javascript Solutions


Solution 1 - Javascript

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).

Solution 2 - Javascript

You can filter the selector by using .not() or :not() selector.

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

OR

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

Solution 3 - Javascript

Try it with the :not() pseudo-class selector: http://api.jquery.com/not-selector/

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHarryView Question on Stackoverflow
Solution 1 - JavascriptI Hate LazyView Answer on Stackoverflow
Solution 2 - JavascriptSushanth --View Answer on Stackoverflow
Solution 3 - JavascriptPez CuckowView Answer on Stackoverflow