Remove node removeChild()
removeChild() method deletes a node from the child node list. If the deletion is successful, this method can return the deleted node, if it fails, it returns NULL.
Syntax:
nodeObject.removeChild(node)
Parameters:
node: Required, specify the node to be deleted.
Note: Assign the deleted child node to x. This child node is not in the DOM tree, but it still exists in the memory and can be operated through x.
If you want to completely delete the object, assign null value to x.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> </head> <body> <p id="content"> <h1>html</h1> <h1>php</h1> <h1>javascript</h1> <h1>jquery</h1> <h1>java</h1> </p> <script type="text/javascript">//一次性删除所有子节点function clearText() { var content=document.getElementById("content"); for(var i=0;i<content.childNodes.length;i++){ var node = content.childNodes[i]; content.removeChild(node); } }</script> <button onclick="clearText()">清除节点内容</button> </body> </html>
The above is the detailed content of Introducing the usage of delete node function removeChild(). For more information, please follow other related articles on the PHP Chinese website!