Traditionally, a suggested way of removing a node\'s children in Javascript is to do something like this:
while(node.firstChild) { node.removeChild(node.
node.childNodes is a live collection, so when you remove a child from node in the forEach you mess with the iterator.
node.childNodes
node
https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes