[英]closest() for getting a html value from the previous td
http://jsfiddle.net/twkRY/ http://jsfiddle.net/twkRY/
<table>
<tr>
<td class="iwant">ttt</td>
<td>some text <span class="txt">haha</span></td>
</tr>
</table>
$(".txt").on("click", function() {
alert($(this).closest("td.iwant").html())
})
It just gives undefined. 它只是给未定义。 Why not ttt ?
为什么不ttt ?
edit : i know the solution how to make it work with prev
and parent
, I just want to know why closest
doesn't work. 编辑 :我知道解决方案如何使其与
prev
和parent
一起工作,我只想知道为什么closest
不起作用。
您想要获得closest
td
,然后使用prev
获得先前的兄弟姐妹。
$(this).closest("td").prev(".iwant").html()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.