I have a Row Index
and TD index
in a table and I want to select input
element inside the cell in [Row Index,TD Index]
. How I can do this?
I have a Row Index
and TD index
in a table and I want to select input
element inside the cell in [Row Index,TD Index]
. How I can do this?
3 Answers
Reset to default 9Tables have accessor properties intended for direct access to individual cells, i.e.:
table.rows[rowIndex].cells[colIndex]
hence:
table.rows[rowIndex].cells[colIndex].getElementsByTagName('input')[0];
or:
$('input', table.rows[rowIndex].cells[colIndex])
This should work:
$('tr:eq(rowIndex) td:eq(tdIndex) input')
:eq selector for more information.
var rowIndex = X;
var cellIndex = Y;
$('#my-table tbody')
.children(':nth-child('+(rowIndex+1)+')')
.children(':nth-child('+(cellIndex+1)+')')
.find('input').val('Hello');
of course you can put em all a single selector
$('#my-table tbody tr:nth-child('+(rowIndex+1)+') td:nth-child('+(cellIndex+1)+')')
.find('input').val('Hello');