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

<div id="output"><pre></pre></div>

#parent {
  padding: 20px;
  background: salmon;

#child {
  padding: 20px;
  background: teal;
  color: #fff;

#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.