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

Introducing the usage of delete node function removeChild()

巴扎黑
Release: 2018-05-12 15:34:42
Original
3470 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template