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.
$(document).ready(function()
{
I've just found an interesting trick, which basically consists on counting the previous siblings:
var tr = $(some_selector);
var rowIndex = tr.prevAll().length;
This way you will get 0 if this is the first tr, 3 if this is the 4th tr, etc.
Just for the sake of it, another option using index(), which saves you from having to know how to select the containing table:
var rowIndex = tr.parent().children().index(tr);