[英]Return only one value when table cell contains multiple tr and td
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). 我有一个较小的表,其中包含多个tr和td元素,这是较大的表bgtable的一部分。当我单击该较小的表时,我具有一个定位标记以重定向到某个页面(必须单击较小的表)。 Now my onclick event on this table returning Data1 , Data2 and Data3 all together. 现在我在此表上的onclick事件一起返回Data1,Data2和Data3。 How can I capture only last td data which is Data3 always using Jquery ? 我怎样才能只捕获最后的td数据,而Data3总是使用Jquery? my below code returning all td data which I don't want. 我下面的代码返回我不想要的所有td数据。
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 : 然后我的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". 注意:我无法更改onclick,但必须获取“ Data3”。 Tried ($("td:last".text() )
. Not helpful and returns nothing 尝试过($("td:last".text() )
。没有帮助,什么也不返回
Okay ... finally it is working with below : 好吧...终于可以在下面使用了:
$(this).find("td:last").text() ;
Do anybody knows how to get the one element before last one ? 有人知道如何获得最后一个要素之前的一个要素吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.