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
.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.