The RemoveChild function can delete the specified child elements of the parent element.
If this function deletes a child node successfully, it returns the node that was deleted, otherwise null is returned.
Syntax structure:
Fatherobj.removechild (Childrenobj)
Parameter explanation:
1.FATHEROBJ: The element object to delete the child element.
2.CHILDRENOBJ: The child element object to be deleted.
Special Note:
In Firefox, Google, and IE8 browsers, white space is also a text node, but the blank text node is ignored in IE8 and IE8 browsers, and you can see how JavaScript gets the child node and the parent node section of the element.
Code instance:
Example one:
The above code can delete the second Li element in the child element of box.
Example two:
The above code selects the element node from all the child nodes in box, then puts the element node in an array, and then deletes the second element node.
Summarize:
RemoveChild ()
This function is to get the element's parent element and delete it. The grammatical form is: parent.removechild (child);
Sometimes we want to delete without involving the parent element. But Dom is the mechanism that must be explicit about the element and the parent element before it can be deleted. When we go to the element to be deleted, we can also delete, using its ParentNode property to find the parent element:
var Child=document.getelementbyid (p1);
Child.parentNode.removeChild (child);
Note: jquery also has functions that correspond to RemoveChild: Remove () and empty ()
Remove (): means to delete both itself and the child elements
Empty (): Is to delete child elements