How do i find row from cell content click?
<tr id="autogeneratedrowid_gridrow1">
<td>1</td>
<td>2</td>
<td>
<table id="unitprice">
<tbody>
<tr>
<td>
<A class=link2 id="aurogenerated" onclick="setMode(this); return false;">Edit</A>
</td>
</tr>
</tbody&开发者_如何学Cgt;
</table>
</td>
</tr>
<tr id="autogeneratedrowid_gridrow2">
.....
.....
</tr>
This is my rendered html code when i click on link button setMode function is called & i m passing 'this' means link button to the function I want to find gridrow when link button is click using Jquery? I am using this
$("#" + lnkBtn.id).parent().parent().parent().parent().parent().parent();
but this is not a right way of doing it
As your ids are autogenerated, you could do this:
$("#" + lnkBtn.id).closest("table").closest("tr");
What closest
does, is to find the closest antecessor that matches the selector.
EDIT:
My above solution solves your problem. But a better solution (if you can change the html markup), would be to add a class to your all your row tr
s, lets's say 'rowClass', like this:
<tr id="autogeneratedrowid_gridrow1" class='rowClass'>
And then your selector would be this:
$("#" + lnkBtn.id).closest(".rowClass");
Hope this helps. Cheers
you can use closeset
http://api.jquery.com/closest/
$("#" + lnkBtn.id).parent().closest('tr')
$('.link2').closest('table').closest('tr');
$("#" + lnkBtn.id).parents('tr').index());
This code will give the index of the row, hope this will help you.
精彩评论