12

I want to know if there is a way to hide parent element of an identified element.

for example:

<div>
<span id="abx">some garbage content</span>
<div>other garbage containers not having any class or id</div>
</div>

The custom filter of AdBlockPlus to select abx will be:

##span#abx

But how to select its parent element? because we need to hide all siblings of identified element.

Krzysztof Kot
  • 648
  • 1
  • 10
  • 15
Raheel Hasan
  • 5,753
  • 4
  • 39
  • 70
  • (moving this as a comment) It may be possible to find a workaround by looking at the problem from a different angle. E.g. If all your other divs have id or class, you could filter them out like div:not([class]):not([id]) – Zlatin Zlatev Aug 24 '16 at 09:54

3 Answers3

8

You can't do that, because of limitations of CSS 3.

It will be possible after implementation of the relational pseudo-class: :has() from Selectors Level 4, with following syntax:

example.com##div:has(> #abx)

Current support for this feature.

Przemek
  • 3,855
  • 2
  • 25
  • 33
4

You can use an AdblockPlus CSS selector.

#?#div:-abp-has(span###abx)

https://help.adblockplus.org/hc/en-us/articles/360062733293-How-to-write-filters#elemhide-emulation

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
Mark Choi
  • 420
  • 6
  • 16
2

It would be possible using relational pseudo class :has but it is not currently supported.

(Subject selector is removed from specification: http://css4.rocks/selectors-level-4/subject-of-selector.php)

This feature has not been part of CSS before because of performance.

There is polyfill in uBlock Origin.

Krzysztof Kot
  • 648
  • 1
  • 10
  • 15