Home >Backend Development >PHP Tutorial >Example of JS implementation of DOM deletion node operation

Example of JS implementation of DOM deletion node operation

不言
不言Original
2018-04-04 17:16:112178browse

This article mainly introduces the JS implementation of DOM node deletion operation, and analyzes the related implementation techniques of JavaScript using removeChild() to operate the page dom node deletion function in the form of examples. Friends in need can refer to this article

The example describes the JS implementation of DOM node deletion operation. Share it with everyone for your reference, the details are as follows:

1 Introduction

Delete nodes by using the removeChild() method to fulfill.

removeChild() method is used to delete a child node.

obj. removeChild(oldChild)<br>oldChild: Indicates the node that needs to be deleted.

Second application

Delete the node. This example will dynamically delete the page through the removeChild() method of the DOM object. Selected text.

Three codes

<!DOCTYPE html>
<html>
<head>
<title>www.jb51.net 删除节点</title>
<script language="javascript">
<!--
function delNode()
{
var deleteN=document.getElementById(&#39;di&#39;);
if(deleteN.hasChildNodes())
{
  deleteN.removeChild(deleteN.lastChild);
}
}
-->
</script>
</head>
<body>
<h1>删除节点</h1>
<p id="di">
<p>第一行文本</p>
<p>第二行文本</p>
<p>第三行文本</p>
</p>
<form>
<input type="button" value="删除" onclick="delNode();"/>
</form>
</body>
</html>

Four running results

Related recommendations:

js---DOM node

JS How to manipulate DOM with JQuery

##

The above is the detailed content of Example of JS implementation of DOM deletion node operation. 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