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

Time:05-21

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.

CodePudding user response:

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 anymore:

//a[contains(text(),"Promoted by")]
//a[text()="Promoted by"] (exact match)
  • Related