I have two rows of an html table:
<table id="mytable">
<tbody>
<tr><td rowspan="2">Row text</td><td>first cell</td><td>second cell</td><td>third cell</td></tr>
<tr>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
</tr>
</tbody>
</table>
I have to get the text of respective cell from first row while click on any input field of second row. As for example, if any user clicks on first input field of second row, 'first cell' should be get by jQuery. I am trying to achieve this as below:
$('#mytable tbody tr td input[type="text"]').click( function(){
var thisRow = $(this).closest('tr').index();
var thisCell = $(this).closest('td').index();
var upRow = thisRow-1;
var firstCellText = upRow.find('td:eq(thiscell+1)').text();
alert(firstCellText);
});
but the text is not getting as expected. How to get the text?