title: javascript: getting td index
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/788225/table-row-and-column-number-in-jquery">Table row and column number in jQuery</a>  </p>
  </blockquote>
  
  
  
  <p>If I have a table like so:</p>
  
  <pre><code>&lt;table&gt;
    &lt;thead&gt;
       &lt;tr&gt;&lt;th&gt;1&lt;/th&gt; &lt;th&gt;2&lt;/th&gt; &lt;th&gt;3&lt;/th&gt;&lt;/tr&gt;
    &lt;/thead&gt;
  
    &lt;tbody&gt;
      &lt;tr&gt;&lt;td&gt;data&lt;/td&gt; &lt;td&gt;checkbox&lt;/td&gt; &lt;td&gt;data&lt;/td&gt;&lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>When the user clicks the checkbox, I want to get the row and column indices. I can get the row index by using this code: </p>
  
  <pre><code> var row = $(this).parent().parent();
   var rowIndex = $(row[0].rowIndex);
  </code></pre>
  
  <p>but I can't figure out the column index...</p>
  
  <p>I tried this but it didn't work:</p>
  
  <pre><code> var colIndex = $(row.children().index(this).parent());
  </code></pre>
  
  <p>I looked through the results of similar questions here and it seems I have to iterate through all the tds with each or map, is there something simpler that I can use? Thanks.</p>