How to remove a hidden HTML element?

I am trying to remove 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 cannot get the handle to the element because it is hidden.

Missed Error: NOT_FOUND_ERR: DOM 8 elementHidden exception

Is there a way to remove a node that is hidden using pure JavaScript? Due to conflicts, I cannot 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); 
+4
source share
1 answer

To remove a node, you must call https://developer.mozilla.org/En/DOM/Node.removeChild , this is not a document method. It doesn't matter if it is a hidden element or not

 function removeElement(el) { el.parentNode.removeChild(el); } 
+4
source

Source: https://habr.com/ru/post/1390358/


All Articles