Hello, I have a table. In this table have select element. How can I find in which table row is select element, from within the select's event handler:
$('#selectElemID').live('change', function(){...});
Thanks
Hello, I have a table. In this table have select element. How can I find in which table row is select element, from within the select's event handler:
$('#selectElemID').live('change', function(){...});
Thanks
This should do it, if you want the row number of the current select element (which is what I understand from the question):
$('#selectElemID').live('change', function(){
alert($(this).closest("tr").prevAll("tr").length + 1);
});
To explain:
$(this).closest("tr")
means select the closest parent tr
of this select element.
.prevAll("tr").length + 1
means select all the previous rows, and get me the length of the returned collection. Increment it by one to get the current row number, because we are at total previous rows + 1.
For more information:
also:
$('#selectElemID').live('change', function(){
alert($(this).closest("tr")[0].rowIndex);
});