title: Search the table by cell content with jquery and relative referencing
body: <p>Having such table</p>
  
  <pre><code>&lt;table&gt;
  &lt;thead&gt; ... &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr class="TableOdd"&gt;
      &lt;td class="TableCol0"&gt; 1 &lt;/td&gt;
      &lt;td class="TableCol1"&gt; x &lt;/td&gt;
      &lt;td class="TableCol2"&gt; x &lt;/td&gt;
      &lt;td class="TableCol3"&gt; # &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr class="TableEven"&gt;
      &lt;td&gt;....&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>E.g. each cell has own class indicating it's column number <code>TableCol0,1,2..N</code></p>
  
  <p>In each row, needed compare the content of the cells in column 1 and 2 and write the result into colum3.</p>
  
  <p>Managed the following script,</p>
  
  <pre><code>$(document).ready(function() {
  var toterr = 0;
  $('tbody tr.TableEven,tbody tr.TableOdd').each(function() {
      var wanted = $(this).find('.TableCol1' ).html();
      var actual = $(this).find('.TableCol2' ).html();
  //console.log('wanted='+wanted+'=actual='+actual+'=');
      if ( wanted == actual ) {
          $(this).find('.TableCol3').text('ok');
      } else {
          $(this).find('.TableCol3').text('ERROR');
          toterr++;
      }
  });
  $('#totalerror').text(toterr);   
  });
  </code></pre>
  
  <p>It is probably not optimal, but works.</p>
  
  <p>Now have a bit different scenario: Need compare two cells what are before a cell with a specified content (<code>:CMP:</code>), e.g:</p>
  
  <pre><code>&lt;table&gt;
  &lt;thead&gt; ... &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr class="TableOdd"&gt;
      &lt;td class="TableCol0"&gt; x &lt;/td&gt;
      &lt;td class="TableCol1"&gt; x &lt;/td&gt;
      &lt;td class="TableCol2"&gt; :CMP: &lt;/td&gt;
      &lt;td class="TableCol3"&gt; etc &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr class="TableEven"&gt;
      &lt;td class="TableCol0"&gt; N &lt;/td&gt;
      &lt;td class="TableCol1"&gt; x &lt;/td&gt;
      &lt;td class="TableCol2"&gt; y &lt;/td&gt;
      &lt;td class="TableCol3"&gt; :CMP: &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>For each row, need compare cells what are before <code>:CMP:</code>, and replace the <code>:CMP:</code> with the result. e.g.</p>
  
  <ul>
  <li>in the 1st row need compare the <code>x</code> and <code>x</code> and write <code>ok</code> in the cell <code>.TableCol2</code></li>
  <li>in the 2nd row need compare the <code>x</code> and <code>y</code> and write ERROR in the cell <code>.TableCol3</code></li>
  </ul>
  
  <p>I haven't idea how to modify the above script.</p>