title: jQuery: finding ancestors siblings with matching content / tree walking
body: <pre><code>&lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
       &lt;td class="TargetRow"&gt;Not this one&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
      &lt;tbody&gt; ... &lt;/tbody&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
       &lt;td class="TargetRow"&gt;This one&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
      &lt;tbody&gt; ... &lt;/tbody&gt;
      &lt;tbody&gt;
          &lt;tr class="ContextRow"&gt; ... &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Given the above HTML I'm trying to find a way of getting the contents of the preceding <strong>tr</strong> of class <strong>TargetRow</strong>.  I.e. for the first preceding tbody that contains a <strong>td.TargetRow</strong> return the <strong>td.TargetRow</strong></p>
  
  <p>I'm using jQuery, at present I can get hold of the <em>tbody</em> containing the ContextRow using:</p>
  
  <pre><code> jQuery(contextRow).parents("tbody").first()
  </code></pre>
  
  <p>How can I now find the previous sibling of that <em>tbody</em> that contains <em>tr.ContextRow</em>?</p>
  
  <p>If there was just a way for me to say from <strong>contextRow</strong> walk up the DOM tree until you find an element matching <strong>"td.TargetRow"</strong> then that would be ideal.</p>
  
  <p>Many Thanks.</p>