title: jQuery - Count number/Get Index of rowspan rows
body: <p>I'm trying to figure out how to get the index of the current rowspanned "row" (even though its the cell that is rowspanned).</p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;td rowspan="2"&gt;First&lt;/td&gt;
          &lt;td&gt; First 1 1 &lt;/td&gt;
          &lt;td&gt; First 2 1 &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
           &lt;td&gt; First 2 1 &lt;/td&gt;
           &lt;td&gt; First 2 2 &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td rowspan="2"&gt;Second&lt;/td&gt;
          &lt;td&gt; Second 1 1 &lt;/td&gt;
          &lt;td&gt; Second 2 1 &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
           &lt;td&gt; Second 2 1 &lt;/td&gt;
           &lt;td&gt; Second 2 2 &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>If I clicked on any cell in the table, how can I count which "row-spanned" row I'm at?</p>
  
  <p>For example if I click on any of the "Second" cells, I should get "2" and if I click on any of the "First" cells, I should get "1".</p>
  
  <p>I've tried multiple things include this:</p>
  
  <pre><code>row=$(this).parent().parent().children('tr').filter(function (index) {
      return $(this).children('td[rowspan]'); }).index($(this).parent());
  </code></pre>
  
  <p>and</p>
  
  <pre><code>row=$(this).parent().parent().children('tr:contains("td[rowspan]")')
      .parent().parent().index($(this).parent());
  </code></pre>
  
  <p>and sort-of got it to work with</p>
  
  <pre><code>$row=$(this).parent();
  while ($row.children('td:eq(0)').attr("rowspan").length&lt;=0)
      $row=$row.prev();
  span=$row.children('td:eq(0)').attr("rowspan");
  row=Math.floor( parseInt($(this).parent().parent().children().index( $(this).parent()) )/span );
  </code></pre>
  
  <p>but this will only work give that there is a rowspan cell... and is assuming that all rows have that same rowspan</p>
  
  <p>I tried working off these site, but couldn't get too far.</p>
  
  <p><br />
  <a href="https://stackoverflow.com/questions/2931893/jquery-selector-to-count-the-number-of-visible-table-rows">jquery selector to count the number of visible table rows?</a>
  <br />
  <a href="https://stackoverflow.com/questions/3585272/jquery-how-to-select-rows-from-a-table">JQuery: How to select rows from a table</a>
  <br />
  <a href="https://stackoverflow.com/questions/788225/table-row-and-column-number-in-jquery">Table row and column number in jQuery</a></p>