title: How to find the index of a row in a table using jquery
body: <p>I'm trying to find the index of a row in a table. I'm trying to use the following code, but I seem to get an index of -1.</p>
  
  <pre><code>$(document).ready(function()
  {
      $("tr").click(function (){
          var index = $("table").index($(this));
          $("span").text("That was row index #" + index);
      });
  });
  </code></pre>
  
  <p>With html that looks like this;</p>
  
  <pre><code>&lt;table&gt;
  &lt;tbody&gt;
      &lt;tr&gt;&lt;td&gt;click&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;click&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;click&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;click&lt;/td&gt;&lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p></p>
  
  <p>Thanks</p>