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:


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

| improve this answer | |
  • 7
    Why? Could you give explanation? – Toto Feb 1 '18 at 12:42
  • 3
    That's the proposed CSS4 syntax, and many adblockers have already implemented it. uBlock Origin has it, for example. – Rod Boev May 29 '18 at 10:57
  • 1
    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 '18 at 18:36
  • Why is RegEx needed? Shouldn't OP's non-regex code work? – RedDragonWebDesign Jul 3 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.

| improve this answer | |

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:

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.