I'm not sure if "lowest common ancestor" is the right term, I also think that this problem should be quite common, I have tried to find the solutions online, but couldn't find it.
So I have below structure:
<div> <!-- A -->
<div> <!-- B -->
<div> <!-- C: I need to select this element -->
<div>
<div>
<div>
random string
<div>
<div>
SOMETHING
</div>
<div>
SOMETHING
</div>
</div>
</div>
</div>
</div>
<div>
<div>
<div>
SOMETHING
</div>
</div>
</div>
<div>
<div>
<div>
SOMETHING
</div>
</div>
</div>
<div>
<div>
<div>
SOMETHING
</div>
</div>
</div>
<div>
<div>
<div>
SOMETHING
</div>
</div>
</div>
</div>
<div>
random string
</div>
</div>
<div>
random string
</div>
</div>
My goal is to select that first/lowest element (in this case it's div C) that contains all children/descendants that contain string "SOMETHING".
The closest solution that I got was using xpath: //*[contains(text(),"SOMETHING")]/ancestor::*
, but using this will return basically any elements that contain "SOMETHING" (it does return the div C, but also returns other elements, I only want to get the div C).
The solution doesn't have to be using xpath, but vanilla javascript is preferrable, also it doesn't have to be very efficient. Thanks in advance.