I have a smaller table with multiple tr and td elements which is part of bigger table bgtable .When I click on that smaller table I have a anchor tag to redirect to some page (this must have to be on click on smaller table). Now my onclick event on this table returning Data1 , Data2 and Data3 all together. How can I capture only last td data which is Data3 always using Jquery ? my below code returning all td data which I don't want.
so
<a href="www.example.com">
<table>
<tr>
<td> Data1 </td>
</tr>
<tr>
<td> Data2 </td>
</tr>
<tr>
<td> Data3 </td>
</tr>
</table>
</a>
then my JQ :
$(document).ready(function() {
$(".bgtable td").on("click", function() {
console.log($(this).text());
});
});
Note: I can't change my onclick but I have to get the "Data3". Tried ($("td:last".text() )
. Not helpful and returns nothing
Okay ... finally it is working with below :
$(this).find("td:last").text() ;
Do anybody knows how to get the one element before last one ?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.