title: How do I check if a div contains another div?
body: <p>I need to show alert if my parent div has a child div using JavaScript only No jQuery.</p>
  
  <p>I have tried using the <code>contains()</code> function to check my div and send alert but it's not working.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script type="text/javascript"&gt;
    var parentDiv = document.getElementById("commentBox");
    var childDiv = document.getElementById("comment1");
    if (parentDiv.contains(childDiv)) {
      alert("yes");
    } else
    {
      alert("no");
    }
  &lt;/script&gt;
  &lt;div class="row leftpad collapse" id="commentBox"&gt;
    &lt;div id="comment1"&gt;
      &lt;div class="col-md-3 dir-rat-left"&gt; &lt;i class="fa fa-user-circle" aria-hidden="true"&gt;&lt;/i&gt;
        &lt;h6&gt;James &lt;/h6&gt;
      &lt;/div&gt;
      &lt;div class="col-md-9 dir-rat-right"&gt;
        &lt;p class="removemarg"&gt;always available, always helpfull that goes the same for his team that work with him - definatley our first phone call.&lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>There should be an alert box with message <code>yes</code> in it but it's not visible. I have also tried checking JavaScript using the <code>alert()</code> method only without any code.</p>