xxxxxxxxxx
const node = document.getElementById("node");
node.parentNode.removeChild(node);
xxxxxxxxxx
//remove a dom element
var element = document.getElementById("someId");
element.parentNode.removeChild(element);
//remove element from array
var colors=["red","green","blue","yellow"];
var blue=colors.splice(2, 1);//first arg is array index to remove
//colors is now ["red","green","yellow"]
xxxxxxxxxx
const labelEmail = document.getElementById('label-email');
labelEmail.remove();
xxxxxxxxxx
// delete an element from the dom
var elem = document.querySelector('#some-element');
elem.parentNode.removeChild(elem);
// keep element in dom
var elem = document.querySelector('#some-element');
elem.style.display = 'none';
xxxxxxxxxx
// Get the element you want to remove
var element = document.getElementById(elementId);
// Get the parent and remove the element since it is a child of the parent
element.parentNode.removeChild(element);
xxxxxxxxxx
// Assuming the user wants to remove an element with id "myElement"
// Get the element to be removed
var elementToRemove = document.getElementById("myElement");
// Check if the element exists
if (elementToRemove) {
// Remove the element from its parent node
elementToRemove.parentNode.removeChild(elementToRemove);
} else {
console.log("Element not found.");
}
xxxxxxxxxx
// Get the HTML element you want to remove
var elementToRemove = document.getElementById("elementId");
// Remove the element from the DOM
elementToRemove.parentNode.removeChild(elementToRemove);
xxxxxxxxxx
const element = document.getElementById("element")
div.parentNode.removeChild(div);
element.parentNode.removeChild(element);