题解 | #dom 节点查找#
dom 节点查找
http://www.nowcoder.com/practice/74d74be449af4c66907fe2d6961c255c
使用DOM中Node接口的parentNode指针获取父节点,思路同LC236
function commonParentNode(oNode1, oNode2) { let set = new Set(); let tmp = oNode1; while(tmp) { set.add(tmp); tmp = tmp.parentNode; } let res = oNode2; while(res) { if(set.has(res)) return res; else res = res.parentNode; } }