title: Testing objects for ancestor/descendent relationship in JavaScript or Jquery
body: <p>I'm trying to come up with a reusable JS or jQuery function that would allow me to test if one object is a DOM descendant of another. </p>
  
  <p>I've seen a model of testing for </p>
  
  <pre><code>$b.parents('nodename').length&gt;0
  </code></pre>
  
  <p>Which is fantastic when you only need to check if an element is a child of any node by that name.</p>
  
  <p>But what about a specific node? You can't test</p>
  
  <pre><code>$b.parents($a).length&gt;0
  </code></pre>
  
  <p>Because jQuery parents takes a nodename expression as an argument to filter.</p>
  
  <p>As a little background, I'm trying to test if a document click event's target is a child of a specific object. For instance, if the event.target is a child of $b, return true, otherwise, return false. But this function could have other implications later on.</p>
  
  <p>Thanks!</p>