I'm now implementing something like this post (specifically, the effect takes place when the row is clicked)
How do I know what the index of the row is inside the table?
JavaScript Array findIndex() The findIndex() method executes a function for each array element. The findIndex() method returns the index (position) of the first element that passes a test. The findIndex() method returns -1 if no match is found.
var Something = $(this). closest('tr'). find('td:eq(1)'). text();
If you defined the click handler directly on the tr
elements, you can use the index
method like this:
$('#tableId tr').click(function () {
var rowIndex = $('#tableId tr').index(this); //index relative to the #tableId rows
});
If the click event is bound not directly on the tr
element (if you are using an anchor, a button, etc...), you should find the closest tr
to get the right index:
$(selector).click(function () {
var rowIndex = $('#tableId tr').index($(this).closest('tr'));
return false;
});
Try an example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With