Excerpted from www.w3school.com:http://www.w3school.com.cn/htmldom/dom_elements.asp
To delete an HTML element, you must be aware of the element's parent element:
<DivID= "Div1"><PID= "P1">This is a paragraph.</P><PID= "P2">This is another paragraph.</P></Div><Script>varParent=document.getElementById ("Div1");var Child=document.getElementById ("P1");p arent.removechild (child);</Script>
This HTML document contains a <div> element with two child nodes (two <p> elements):
<DivID= "Div1"><PID= "P1">This is a paragraph.</P><PID= "P2">This is another paragraph.</P></Div>
Find elements of Id= "DIV1":
var Parent=document.getelementbyid ("Div1");
Find the <p> elements of Id= "P1":
var Child=document.getelementbyid ("P1");
To remove a child element from the parent element:
Parent.removechild (child);
Tip: Can I delete an element without referencing the parent element?
I'm so sorry. The DOM needs to understand the elements you need to delete, as well as its parent elements.
Here's a common workaround: Find the child element you want to delete, and use the ParentNode property to find its parent element:
var Child=document.getelementbyid ("P1"); Child.parentNode.removeChild (child);
htmldom-Delete an existing HTML element