Topic describes

Find the nearest common parent of two nodes, including the nodes themselves

Input description:

ONode1 and oNode2 are in the same document and will not be the same node

function commonParentNode(oNode1, oNode2) {
    if(oNode1.contains(oNode2)){
        return oNode1
    }else{
        return commonParentNode(oNode1.parentNode,oNode2)
    }
}
Copy the code