Replacing Nodes Error. The node to be replaced is not a child of this node
In replaceChild
, the new node is the first argument, not the second. You have them backwards.
parentNode.replaceChild(newNode, currentSelectList);
Also, why would you do i--
? Isn't that creating an infinite loop?
currentSelectList.replaceWith(newNode)
Use modern vanilla JS! Way better/cleaner than before. Generic form:
target.replaceWith(element);
developer.mozilla.org
Can I Use - 94% May 2020