You can use the index() with parentsUntill() to the parent TR element of that TD.
The index() is an inbuilt method in jQuery which is used to return the index of the a specified elements with respect to selector. Parameter: It accepts an optional parameter “element” which is used to get the position of the element. Return value: It returns an integer denoting the index of the specified element.
I can get the row index by using this code: var row = $(this). parent(). parent(); var rowIndex = $(row[0].
btnSelect',function(){ // get the current row var currentRow=$(this). closest("tr"); var col1=currentRow. find("td:eq(0)"). text(); // get current row 1st TD value var col2=currentRow.
With plain JavaScript:
// table is a reference to your table
table.rows[rowIndex].cells[columnIndex]
Reference: HTMLTableElement
, HTMLTableRowElement
With jQuery, you could use .eq()
:
$('#table tr').eq(rowIndex).find('td').eq(columnIndex)
// or
$('#table tr:eq(' + rowIndex + ') td:eq(' + columnIndex + ')')
How about using the nth-child
selector?
http://api.jquery.com/nth-child-selector/
var row = 4;
var col = 2
var cell = $('table#tableId tr:nth-child(' + row + ') td:nth-child(' + col + ')');
Note that the child index is 1-based, rather than the more usual 0-based.
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