javascript remove dom element
var elem = document.querySelector('#some-element');
elem.parentNode.removeChild(elem);
javascript remove dom element
var elem = document.querySelector('#some-element');
elem.parentNode.removeChild(elem);
delete node in javascript
<ul id="shoppinglist">
<li class="complete"> Apple [<a href="#">Delete</a>] </li>
<li class="complete"> banana [<a href="#">Delete</a>]</li>
<li class="complete"> mango [<a href="#">Delete</a>]</li>
<li class="complete"> guava [<a href="#">Delete</a>]</li>
</ul>
// Set up event listeners to call itemDone() on click
document.getElementById("shoppinglist").addEventListener('click', function(e) {
deleteNode(e);
}, false);
function deleteNode(e) {
var target, elParent, elGrandParent;
//Remove Item From the list
target = e.target;
// alert(e.target.value);
elParent = target.parentNode;
elGrandParent = elParent.parentNode;
alert(target.parentNode.innerHTML + " Removed From Cart")
elGrandParent.removeChild(elParent);
//prevent the link from taking you elsewhere
e.preventDefault();
}
Removing DOM nodes when traversing a NodeList
NodeList nodes = ...;
for (int i = nodes.getLength() - 1; i >= 0; i--) {
Element e = (Element)nodes.item(i);
if (certain criteria involving Element e) {
e.getParentNode().removeChild(e);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us