Reputation: 8548
If I get elementA
and elementB
with document.querySelector
, how to can I check if elementA
is a child element of elementB
without jQuery
?
Considering elementA
maybe not first level child of elementB
.
Exemple: http://jsbin.com/jijoqicozo/edit?html,js,output
Upvotes: 1
Views: 60
Reputation: 557
You can use B.contains(A) to determine if element A is a descendent of element B.
Note that node.contains is inclusive, meaning that B.contains(B) === true
https://developer.mozilla.org/en/docs/Web/API/Node/contains
Upvotes: 4