0

I'm using :not() pseudoclass this way:

:not(_)

to increase the specificity of my selector. It does its job but I would like to know what is the meaning of this underscore and what impact on specificity (0,0,0) it has.

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Ryszard Jędraszyk
  • 2,296
  • 4
  • 23
  • 52

1 Answers1

1

That's a simple Type selector, just one you're unlikely to find in normal circumstances.

var el = document.createElement('_');
document.body.append(el);
el.textContent = 'Hello';
_{ color: green; }
Say 

Moreover when <_> markup wouldn't be valid.

<_>hello</_>
Kaiido
  • 123,334
  • 13
  • 219
  • 285
  • 1
    Thanks, in such case it will have (0,0,1) specificity and I could use for example `:not(p)` if the element I want to select is not a paragraph. As you mentioned `_` is unlikely to be found and that's the reason `:not(_)` was used - it almost never has any effect other than increasing specificity. – Ryszard Jędraszyk Aug 31 '19 at 13:52
  • 2
    @RyszardJędraszyk you can also increase the specificity using a random ID selector `:not(#sp_r84dt5)`. – Temani Afif Aug 31 '19 at 14:00
  • @TemaniAfif This is great advice, I initially intended to ask about a better way than multiple `:not(.random-class)`, this solves my problem entirely, I feel so stupid now! – Ryszard Jędraszyk Aug 31 '19 at 14:06
  • @Ryszard Jędraszyk: That's the idea, as explained here: https://stackoverflow.com/questions/28299817/can-type-selectors-be-repeated-to-increase-specificity/28300471#28300471 – BoltClock Sep 02 '19 at 03:38