parent element contains the child element.parent is not the same element as child.Node.contains() to check if the parent element contains the child element.const elementContains = (parent, child) =>
parent !== child && parent.contains(child);
elementContains( document.querySelector('head'), document.querySelector('title') ); // true elementContains(document.querySelector('body'), document.querySelector('body')); // false
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️