我正在尝试在表行中查找子元素。代码在下面的链接中。我无法在表行中找到 anchor 标记。我在这里做错了什么?
<a href="##" class="clickevent">Click Here</a>
<table>
<tr id="test_tr">
<td>
<a href="##" class="secondlink">Add New Row</a>
</td>
</tr>
<table>
JS:
$(document).ready(function() {
$(".clickevent").click(function(e){
e.preventDefault();
alert($("#test_tr").find(".secondlink").tagName);
});
});
最佳答案
您必须记住 jQuery Element 对象和实际 Element 之间存在差异。
alert($("#test_tr").find(".secondlink")[0].tagName);
执行[0]
是有效的,因为jQuery也是一个DOM Element对象数组,还有$.get .
关于jquery - 查找表行中的子元素( anchor 标记),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5735783/