Reputation: 5224
I have successfully implemented <table>
<tr>
click event using jQuery in which i get the value of required <td>
of selected row using following where .taglib-search-iterator is my table class,
$(".taglib-search-iterator tbody").on("click", "tr", function(e){
alert($(this).find("td").eq().html());});
But as per my requirement I need to neglect first <tr>
row of the table and second last and last column <td>
of table. So for that I have done the following,
$(".taglib-search-iterator tbody tr:not(:first-child) td:not(:nth-last-child(2))").click(function(){
alert('Right position clicked');
});
Now my problem is I am unable to retrieve the value of <td>
in 7th column when click event is triggered.
I have done following
alert($(this).eq(7).html());
But it returns undefined.Also i have tried simply using
alert($(this).html());
And it is returning value of the <td>
i clicked.
Question?
How can i retrieve value of specific <td>
?
To add, <td>
,<tr>
are auto-generated so it is associated with dynamic class and id and thus cannot be used.
Upvotes: 1
Views: 2573
Reputation: 222428
Use .closest(selector)
to get the nearest ancestor matching selector
alert($(this).closest("tr").children("td").eq(7).html());
Upvotes: 4