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. 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
Is there any way to delete a node that is hidden using pure JavaScript? Due to conflicts, I can’t use any libraries like jQuery.
code from 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. It does not matter whether it’s a hidden element or not