问题
Is it possible to match all nodes that have a data-*
attribute using only CSS?
Here are examples of attributes I would like to match:
data-scope
data-sessionlink
data-visibility-tracking
I could do
*[data-scope] *[data-sessionlink] *[data-visibility-tracking]
but I am looking for something more compact. Furthermore, I don't know all possible data-*
attributes I might encounter in my application.
回答1:
It is currenly impossible to use wildcard masks to select elements by an attribute-name part.
There is a recent thread in the www-style@w3.org mailing list, where Simon Pieters from Opera has proposed a nice possible syntax that has got some acceptance in the thread, so there is a chance that it will become standard somewhen in the future:
x-admin-* { ... }
[data-my-*] { ... }
来源:https://stackoverflow.com/questions/36874331/universal-css-selector-to-match-any-and-all-html-data-attributes