1var elem = document.querySelector('#some-element');
2elem.parentNode.removeChild(elem);
3
1<ul id="shoppinglist">
2 <li class="complete"> Apple [<a href="#">Delete</a>] </li>
3 <li class="complete"> banana [<a href="#">Delete</a>]</li>
4 <li class="complete"> mango [<a href="#">Delete</a>]</li>
5 <li class="complete"> guava [<a href="#">Delete</a>]</li>
6 </ul>
7
8
9// Set up event listeners to call itemDone() on click
10document.getElementById("shoppinglist").addEventListener('click', function(e) {
11 deleteNode(e);
12}, false);
13
14
15function deleteNode(e) {
16 var target, elParent, elGrandParent;
17
18 //Remove Item From the list
19 target = e.target;
20 // alert(e.target.value);
21 elParent = target.parentNode;
22 elGrandParent = elParent.parentNode;
23
24 alert(target.parentNode.innerHTML + " Removed From Cart")
25 elGrandParent.removeChild(elParent);
26
27 //prevent the link from taking you elsewhere
28 e.preventDefault();
29}
1NodeList nodes = ...;
2for (int i = nodes.getLength() - 1; i >= 0; i--) {
3 Element e = (Element)nodes.item(i);
4 if (certain criteria involving Element e) {
5 e.getParentNode().removeChild(e);
6 }
7}