Please take a look at the snippet below:
<div>
<div></div>
<div><!-- my target node -->
<div><!-- not my target node -->
<img /><!-- my source node -->
</div>
</div>
</div>
As you can see the img
-elment has two enclosing div
s. I want the first of those two enclosing div
s to be considered the "real" parent (the one I need to find) of the img
-elment because it has a brother div
before so the search ends and the brother div
and the outer enclosing div
are ignored.
In the case there are no siblings at all, the outer div
has to be yielded; in the case the element is not enclosed, the element itself has to be yielded.
I just would like to know how to target the element as I explained via JavaScript.
element.parentNode
? developer.mozilla.org/en-US/docs/DOM/Node.parentNode – Generalship.parentNode
. in fact, you can use .parentNode to follow a node branch all the way up to the root of the tree. – Teller