use contains function of Node - divElement.contains(child)
or this function in case contains does not exists.
function contains(first, second) { var adown = first.nodeType === 9 ? first.documentElement : first; if (first === second) { return true; } if (adown.contains) { return adown.contains(second); } return first.compareDocumentPosition && first.compareDocumentPosition(second) & 16); }
in case you need to return false when the nodes are the same
function notContains(first, second) { var adown = first.nodeType === 9 ? first.documentElement : first; if (first === second) { return false; } if (adown.contains) { return !adown.contains(second); } return first.compareDocumentPosition && first.compareDocumentPosition(second) & 16) !== 16; }
element.parentNode === divElement?