isChild(node1,node2)javascript

时间:2012-02-21 14:36:29

标签: javascript dom

在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

1 个答案:

答案 0 :(得分:6)

function isChild(node1, node2) {
    return node2 && node2.parentNode === node1;
}

DEMO: http://jsfiddle.net/pPaKy/