I use XPath on DOM when I want to find the n-th parent from a particular node. This is very easily done with XPath vs. selectors.
<body>
<div><!-- you want this one -->
ok
<div id="the-child"></div>
</div>
<div><!-- you dont want this one -->
nok
<div id="the-wrong-child"></div>
</div>
</body>
css: div:has( > #the-child)
xpath: //div[@id="the-child"]/..
isnt that kinda the same? I think I'd even consider the css version to be easier to understand at a glance.If you've got full control over the Dom it'd be much better to just set an id attribute on the element in question though, as getElementById is still the best performing option
css:
div:has( > \* > \* > \* > \* > \* > \* > \* > #the-child)
(backslashes added by hn because of formatting conflict)
xpath: //div[@id="the-child"]/../../../../../../../..