Search code examples
csscss-selectorspseudo-class

Is there a native CSS replacement for :has-text()?


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.


Solution

  • 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)