Delete dom element from document but save it as a variable?

Is there a way to remove the dom element from the document, but save it as a variable? I assume that I need to save the clone as var and then delete the original?

In addition, whether such a style will store styles, etc.

+4
source share
1 answer

Yes, this is what you do.

var savedElement = document.getElementById('element_that_you_want_to_save'); savedElement.parentNode.removeChild(savedElement); // savedElement will still contain the reference to the object, // so for example, you can do: savedElement.style.height = '100px'; document.getElementById('container').appendChild(savedElement); // etc. 
+7
source

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


All Articles