亲爱的专家,我有以下表结构
<table>
<tr>
<td colspan="2">short description</td>
</tr>
<tr>
<td><a href="Disclose.html">View</a></td>
<td><a class="AgendaNote" href="#">Take Note</a></td>
</tr>
</table>
我想要的点击类 AgendaNote 我需要提取第一个 td 的 href 属性,即“Disclose.html”
我试过了
alert($(this).parent().siblings(":first > a").attr("href"));
但它显示未定义。
请帮助我。
最佳答案
siblings
方法无法以这种方式工作,目标 a
元素不是父 td
元素的同级元素,因此查询失败并且 attr
返回一个 未定义
值,您应该首先选择同级 td
元素,然后选择子元素。
$(this).parent().siblings(":first").children('a').attr("href");
但这里更好的选择是使用 prev
方法:
$(this).parent().prev().children().attr("href");
关于jquery - 从特定表格单元格获取 href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22197053/