Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
141 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...