Reputation: 5358
Efficient way to implement the follwing function in javascript
boolean isChild(node1, node2)
where,
node1 = Considered parent node
node2 = Considered child node
function returns true if node2 is a child of node1 else false
Upvotes: 0
Views: 661
Reputation:
function isChild(node1, node2) {
return node2 && node2.parentNode === node1;
}
DEMO: http://jsfiddle.net/pPaKy/
Upvotes: 6