referencing this javascript dom element code example
Example: java script remowechild an element from the DOM
let node = document.getElementById("nested");
if (node.parentNode) {
node.parentNode.removeChild(node);
}
let node = document.getElementById("nested");
if (node.parentNode) {
node.parentNode.removeChild(node);
}