[英]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.