[英]How do I delete a hidden HTML element?
I'm trying to delete an HTML element after changing its visibility to hidden
, but I get the following error when I run the following code . 我试图在将其可见性更改为hidden
后删除HTML元素,但是当我运行以下代码时出现以下错误。 It looks like I can't get a handle on the element because it is hidden. 看起来我无法处理元素,因为它是隐藏的。
Uncaught Error: NOT_FOUND_ERR: DOM Exception 8 elementHidden 未捕获错误:NOT_FOUND_ERR:DOM异常8 elementHidden
Is there any way to delete a node that is hidden using pure JavaScript ? 有没有办法删除使用纯JavaScript隐藏的节点? Due to conflicts, I can't use any libraries like jQuery. 由于冲突,我不能使用像jQuery这样的库。
code from jsFiddle 来自jsFiddle的代码
function elementHidden(e) {
if (!e.target.style.opacity) {
console.log('Delete this mofo!');
document.removeChild(e.target.parent, e.target);
}
}
document.getElementById("curtain").addEventListener('click', elementHidden, false);
To delete a node, you must call https://developer.mozilla.org/En/DOM/Node.removeChild , it's not a method of the document
. 要删除节点,您必须调用https://developer.mozilla.org/En/DOM/Node.removeChild ,它不是document
的方法。 It does not matter whether it's a hidden element or not 它是否是一个隐藏的元素并不重要
function removeElement(el) {
el.parentNode.removeChild(el);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.