I have following html table layout:
<table id="mytable">
<tbody>
<tr>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td>Some cell text</td>
<td></td>
<td><input type="text" value="" /></td>
<td></td>
</tr>
<tr>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td>Some cell text</td>
<td></td>
<td>Some cell text</td>
<td><input type="text" value="" /></td>
</tr>
</tbody>
</table>
I need to know the current input field index of respective row while click on any input field but can't figure out a way to get it. I can get total number of input fields (length) of each row by following formula:
var thisRow = $(this).closest('tr');
var inputLength = thisRow.find('input[type="text"]').length;
As for example the inputLength for first row is 4 and second row is 3. But how can I get the input index when a user clicks on 2nd input field of first row (it should be 1)?
[note: I can't use td index as alternative of input field index as you may see that there might have been some td which have no input field. As a result, if I run a for loop it can't be performed as I expected.]