title: How can I check if an element is within another one in jQuery?
body: <p>Is there any direct way in JavaScript or jQuery to check if an element is within another one.</p>
  
  <p>I'm not referring to the <code>$(this).parent</code> as the element I wish to find can be a random number steps lower in the tree of elements.</p>
  
  <p>As an example, I would like to check if <code>&lt; div id="THIS DIV"&gt;</code> would be within <code>&lt; div id="THIS PARENT"&gt;</code>:</p>
  
  <pre><code>&lt;div id="THIS_PARENT"&gt;
   &lt;div id="random"&gt;
    &lt;div id="random"&gt;
     &lt;div id="random"&gt;
      &lt;div id="THIS_DIV"&gt;
  (... close all divs ...)
  </code></pre>
  
  <p>So in pseudo code:</p>
  
  <pre><code> if($("div#THIS_DIV").isWithin("div#THIS_PARENT")) ...
  </code></pre>
  
  <p>If there isn't any direct way I'll probably do a function for this but still it's worth asking.</p>