RemoveChild () function usage in JavaScript and removechild
The removechild function can delete the specified child element of the parent element.
If this function successfully deletes a subnode, the deleted node is returned. Otherwise, null is returned.
Syntax structure:
FatherObj. removeChild (childrenObj)
Parameter description:
1. fatherObj: The Element Object of the child element to be deleted.
2. childrenObj: The child element object to be deleted.
Note:
In Firefox, Google, and IE8 browsers, the blank content is also a text node, but the blank text nodes are ignored in IE8 and IE8 browsers, for more information, see section 1 "how to obtain child nodes and parent nodes of an element" in javascript.
Code example:
Instance 1:
<! DOCTYPE html>
The above code deletes the second li element in the child element of the box.
Example 2:
<! DOCTYPE html>
The code above selects the element node from all the child nodes in the box, puts the element node into the array, and then deletes the second element node.
Summary:
RemoveChild ()
This function is used to obtain the parent element of an element and delete it. Syntax format: parent. removeChild (child );
Sometimes we want to delete it without involving the parent element. However, DOM is a mechanism that requires clear elements and parent elements to be deleted. You can also delete the elements to be deleted. You can use the parentNode attribute 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 (): deletes both the user and the child element.
Empty (): deletes child elements.
Articles you may be interested in:
- Precautions for using javascript removeChild
- Js removeChild blind-eye Error
- Memory leakage caused by javascript removeChild
- How to remove javascript node removeChild ()
- Js uses the removeChild method to dynamically Delete div elements
- Example of using javascript to delete an element node removeChild ()
- Javascript removeChild () method for deleting nodes and subnodes