[ACCEPTED]-javascript: getting td index-xhtml

Accepted answer
Score: 32

Get the index of the <td> first, since it is 3 on the way to the <tr>:

var cell = $(this).closest('td');
var cellIndex = cell[0].cellIndex

var row = cell.closest('tr');
var rowIndex = row[0].rowIndex;

Or using the parents()[docs] method 2 along with a multiple-selector[docs], you could do the selection 1 for both at once:

var cellAndRow = $(this).parents('td,tr');

var cellIndex = cellAndRow[0].cellIndex
var rowIndex = cellAndRow[1].rowIndex;

More Related questions