Is there a CSS selector that can target a specific attribute value regardless of its attribute? I am looking for something like [*="value"]
(using a wildcard) or {value}
(a direct value selector).
Asked
Active
Viewed 1,422 times
3

TylerH
- 20,799
- 66
- 75
- 101

VorganHaze
- 1,887
- 1
- 12
- 35
-
2no, you will need js, to search for any attributes and then check the values found (if any) .. – G-Cyrillus Dec 31 '20 at 17:14
-
@tylerH, why did you reopen the question? it seems a valid one for me – Temani Afif Dec 31 '20 at 22:25
-
1@TemaniAfif The dupe target that was chosen seems to be asking about any attribute with any value. This question is asking about any attribute with a *specific value*. Basically inverted what the other one is looking for, so not the same thing at all. – TylerH Dec 31 '20 at 22:27
-
@TylerH I think the other question is asking for *any attribute with any value* which is IMO the generic case of *any attribute with a specific value* – Temani Afif Dec 31 '20 at 22:32
-
1@TemaniAfif I know it's 5 years late, but I've asked OP on that target question to clarify, because it seems unclear at the moment what exactly they're asking for there. If it seems like they're actually asking for "any attribute that contains x/specific value" then I'm happy to delete my answer here and re-close this. – TylerH Dec 31 '20 at 22:32
-
@TylerH I doubt you will get a reply but let's wait – Temani Afif Dec 31 '20 at 22:34
-
2If you look at the [original revision](https://stackoverflow.com/revisions/21222375/1) OP titled it specifically about any data attribute, with no consideration for what the value was. While I agree any attribute with any value is more generic than any attribute with a specific value, the question makes sense as a distinct one when inverted to "attribute selector *based on* a value"... it could certainly be possible for the latter to be achievable with a selector when the former is not (if the W3 spec decided to implement such a thing). – TylerH Dec 31 '20 at 22:36
2 Answers
1
The simple answer is NO. We have to use any of the Basic Selectors or attribute selector.
Here is the list of all the CSS selectors.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors
You cannot find any of the value selector :)

Imran Rafiq Rather
- 7,677
- 1
- 16
- 35
-
2
-
2@G-Cyrillus - this looks like an answer to me. How does it fail to answer the question? – But those new buttons though.. Dec 31 '20 at 17:37
-
2
-
I meant any of the selectors dear friend :) Be it type, id , class, or advanced selectors, or wild card selectors etc .. Just provided an updated list of selectors as well :) – Imran Rafiq Rather Dec 31 '20 at 22:24
1
No. CSS attribute selectors are designed to select based on the attribute (hence the name). If you want to select something based on a value rather than an attribute or attribute value, then just use CSS classes.
Alternatively, you can write a verbose selector that includes all the attributes your document will contain (because you should know that information ahead of time), e.g.:
div[data-value="value"], div[href="value"], div[hello="value"], div[goodbye="value"] {
color: red;
}
<div data-value="value">Red</div>
<div>Black</div>
<div href="value">Red</div>
<div hello="value">Red</div>
<div goodbye="value">Red</div>
<div>Black</div>
<div>Black</div>

TylerH
- 20,799
- 66
- 75
- 101