title: get a common parent for two DOM elements
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3960843/how-to-find-the-nearest-common-ancestors-of-two-or-more-nodes">How to find the nearest common ancestors of two or more nodes?</a>  </p>
  </blockquote>
  
  
  
  <p>I have 2 anchor elements and i need to get the common parent of 2 of them.</p>
  
  <p>Some times they are in a ul, sometimes in a table, or any other way.</p>
  
  <p>I am doing this:</p>
  
  <pre><code>var idParent = $(elem1).parents().filter($(elem2).parents()).first().attr('id');
  </code></pre>
  
  <p>But it doesnt always work,  i finds it element sometimes...</p>
  
  <p>Any better idea? or a way to fix this?</p>
  
  <p>EDIT:
  I want a jquery solution.</p>
  
  <p>Thank you</p>