![](/img/trans.png)
[英]Jquery blur doesn't work in Firefox and Chrome but works in IE9
[英]jQuery .parents([selector]) doesn't work with IE9 and Firefox
<html>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="application/javascript">
$(document).ready(function() {
$("#evaluation_complete").parents("table")[0].remove(); //doesn't work
//this works
//var EvalComplete = document.getElementById("evaluation_complete");
//EvalComplete.parentNode.parentNode.parentNode.parentNode.parentNode.removeChild(
//EvalComplete.parentNode.parentNode.parentNode.parentNode);
});
</script>
<p>Testing little code</p>
<table>
<tbody>
<tr>
<td class="button-left"> </td>
<td class="button-middle" nowrap="true"><div
style="margin: 0px 0px 1px;">
<a class="button-text" name="evaluation_complete"
id="evaluation_complete" href="#">Evaluation Complete</a>
</div></td>
<td class="button-right"> </td>
</tr>
</tbody>
</table>
</body>
</html>
我无法控制表格的设置。 但是,我所知道的只是链接的ID。 我的目标是遍历<table>
元素并将其从DOM中删除。 我也尝试过closest
它。 我在Firefox和IE9中收到的错误是remove
不是一个功能。 注释掉的块有效,但不是很动态。 但是,在Chrome中,它可以完美运行。 感谢您的任何帮助。
当您尝试在本机JS元素而不是jQuery元素上使用.remove()
时,它不起作用:
不是 :
$("#evaluation_complete").parents("table")[0].remove();
但
$("#evaluation_complete").parents("table").eq(0).remove();
要么
$("#evaluation_complete").parents("table").first().remove();
等等
使用[0]
或get(0)
从类似数组的jQuery对象中获取本机JS元素,该对象没有.remove()
方法。
附带说明一下,使用closest()
会更有效,并且可以与上述示例配合使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.