0

I see that MDN Web Docs now lists the :has() pseudo-class among others, but is there something similar to :has-text() from uBlock Origin?

span:has-text(Promoted by) {
  display: none;
}

uBlock Origin has both, so I'm wondering whether I have simply overlooked something on MDN.

john c. j.
  • 725
  • 5
  • 28
  • 81
  • 2
    As the article says, _"Procedural means JavaScript code will find DOM elements that it must hide. A procedural cosmetic filter uses a filter operator that will tell uBO how to find/filter DOM elements to find which DOM elements to target."_ So it's not in native CSS yet. – m4n0 May 20 '22 at 21:16
  • 1
    Safari is the only thing that supports `:has()` but what is it you're really trying to accomplish? Are you looking for a css selector that will search an elements content for a specific string? Because that's not a thing and shouldn't be in what CSS is for anyway. – Chris W. May 20 '22 at 21:17

1 Answers1

2

Unless I'm wrong, this is not possible in CSS.

The "easiest alternative way" is to use XPath, but it's not usable in CSS:

//a[contains(text(),"Promoted by")]
//a[text()="Promoted by"] (exact match)
Stefan Schmidt
  • 3,830
  • 1
  • 24
  • 20
NetSkylz
  • 414
  • 2
  • 8
  • 1
    FWIW, it seems [`:contains()`](https://api.jquery.com/contains-selector/) is not deprecated, but it is jQuery selector, not CSS. – john c. j. May 20 '22 at 21:26
  • @johnc.j. Good point, my memory is playing tricks on me ! I've edited my post to avoid confusion. – NetSkylz May 20 '22 at 21:31
  • 2
    @john c. j.: No, NetSkylz was right, it was deprecated and then removed from the spec; its existence in jQuery is non-standard. See https://stackoverflow.com/questions/4781141/why-doesnt-the-selector-h3nth-child1containsa-work/4781167#4781167 – BoltClock May 24 '22 at 07:09