title: How to check in Javascript if one element is contained within another
body: <p>How can I check if one DOM element is a child of another DOM element? Are there any built in methods for this? For example, something like:</p>
  
  <pre><code>if (element1.hasDescendant(element2)) 
  </code></pre>
  
  <p>or</p>
  
  <pre><code>if (element2.hasParent(element1)) 
  </code></pre>
  
  <p>If not then any ideas how to do this? It also needs to be cross browser. I should also mention that the child could be nested many levels below the parent.</p>