Write a uBlock Origin rule targeting for a given node `div:has-text(Test)` all its siblings.
2/2
Apr 15, 1:11pm

To target all siblings of a node matching div:has-text(Test) using uBlock Origin, you can use the following cosmetic filter rule:

plaintext
div:has-text(Test) ~ *

Explanation:

  • div:has-text(Test) selects the <div> element containing the text "Test".
  • ~ * selects all following siblings of that <div>.

If you want to include both previous and next siblings:

uBlock Origin's cosmetic filters do not support selecting previous siblings directly in CSS. However, you can use the following approach to target all children of the parent (which includes all siblings):

plaintext
div:has-text(Test) > .. > *:not(div:has-text(Test))
  • div:has-text(Test) > .. selects the parent of the <div>.
  • > *:not(div:has-text(Test)) selects all children of the parent except the original <div>.

Note:

  • The second rule is more reliable for targeting all siblings (both before and after).
  • Test the rule in uBlock Origin's element picker to ensure it works as expected for your specific DOM structure.
Apr 15, 1:11pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Le Chat can make mistakes. Check answers. Learn more