I have a table 10x10 in html if I add a function for each td hover, how can I get the cell column and row index?
Thanks.
I have a table 10x10 in html if I add a function for each td hover, how can I get the cell column and row index?
Thanks.
You wouldn't need to know the column and row index to apply a hover effect, you can simply use the hover function
Haave a look at this answer. If you're implementing it yourself then to get row highlighting, you would just either use the pseudo css class :hover
or jump to closest parent <tr>
and apply a css class to background color the children <td>
.
To answer how you get the column and row indexes, use the jQuery .index() command
As others have said, there may be a better way of doing things than trying to find the exact cell location, but if you do need it this should work:
$("td").hover(function() {
var columnIndex = $(this).attr("cellIndex");
var rowIndex = $(this).parent().attr("rowIndex"));
});