<div id="parent">
  <div id="child">I'm the child</div>
  <div id="output"><pre></pre></div>
</div>

#parent {
  display: flex;
  flex-direction: column;
}

#output {
  margin-top: 20px;
}
// elementContains utility function
const elementContains = (parent, child) => parent !== child && parent.contains(child);

// Element pointers
const parent = document.querySelector('#parent');
const child = document.querySelector('#child');
const output = document.querySelector('#output pre');

// Contains check
const isChildContainedByParent = elementContains(parent, child);
const isParentContainedByChild = elementContains(child, parent);

// Output
output.innerText = `Parent Contains Child? ${isChildContainedByParent}\n`;
output.innerText += `Child Contains Parent? ${isParentContainedByChild}\n`;

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.