5

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.

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Vadim
  • 1,916
  • 2
  • 19
  • 39

1 Answers1

3

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-*] { ... }
Marat Tanalin
  • 13,927
  • 1
  • 36
  • 52
  • 1
    Thanks, Marat! I hope that one day we will be able to do wildcard selection on attribute names. – Vadim Apr 27 '16 at 12:20
  • Not the greatest idea though - won't allow you to do [data-my-*='exact match'] because *= clashes with an existing operator – gotofritz Jul 09 '17 at 14:57
  • 1
    @gotofritz Good point. But this could probably be resolved by wrapping the attribute name itself in quotes: `["data-my-*" = "exact match"]` – Marat Tanalin Jul 10 '17 at 11:54