Home  >  Article  >  Web Front-end  >  Introducing the usage of delete node function removeChild()

Introducing the usage of delete node function removeChild()

巴扎黑
巴扎黑Original
2018-05-12 15:34:423400browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn