Is it possible to write a custom filter rule so that any div, span or p and its children are hidden when there is a specific word in the text part, i.e. Trump?

For example, I have this structure

  <a class="..." href="...">Donald Trump said blablabla.</a>

I tried this, but it has no effect:


3 Answers 3


Try ##div>a:has-text(/Trump/)

  • 10
    Why? Could you give explanation?
    – Toto
    Feb 1, 2018 at 12:42
  • 6
    That's the proposed CSS4 syntax, and many adblockers have already implemented it. uBlock Origin has it, for example.
    – Rod Boev
    May 29, 2018 at 10:57
  • 2
    Works for me. I got rid of the Not interested option on YouTube videos. Once in a while, when clicking the hamburger menu on a video(...), I'd accidentally click the first option labeled Not Interested. I usually go into the menu to only add to my Watch later playlist. Sadly, the only way to undo Not interested is to completely wipe all your submissions of Not Interested.... which is extremely frustrating when I'm trying to tailor the YouTube suggestions for me. This is what I used: www.youtube.com##.ytd-menu-service-item-renderer:has-text(Not interested)
    – PeterFnet
    Dec 12, 2018 at 18:36
  • 1
    Why is RegEx needed? Shouldn't OP's non-regex code work? Jul 3, 2020 at 5:42

:has-text() is a procedural cosmetic filter. Those "must always be specific, i.e. prefixed with the hostname of the site(s) on which they are meant to apply."

Procedural cosmetic filters are powerful but to be avoided if possible as they can slow down site loading (JavaScript has to be inserted and visit lots of nodes).

If you still want it, it should look like this:


You can change that behaviour so a non-specific procedural cosmetic filter like ##div>a:has-text(Trump) will work, but it is absolutely not recommended. It will slow down your browser on every page and there's the possibility that errors in external filterlists will go free-turning and produce lots of false positives / overblocking.

You can find that option buried in

  1. uBO Dashboard
  2. Settings
  3. Check "I am an advanced user"
  4. Read and understand the warnings
  5. Click the gears
  6. Change "allowGenericProceduralFilters" to true
  7. Click "Apply changes"

p.s.: Forward slashes like :has-text(/Target words/)are not needed. If you use them, the expression inside will be evaluated as RegEx which will cause even more workload.

  • If I understand correctly, it doesn't necessarily need to visit a lot of nodes - just make your selector (everything before :has-text) nice and specific.
    – Matt M.
    Mar 27, 2022 at 5:35
  • Yes, I think you are right.
    – FatBat
    Mar 29, 2022 at 10:28

It seems has-text selector only works when a top level domain is given. So the following works, for example, but only on the Guardian website:


You must log in to answer this question.