Example of JS implementation of DOM deletion node operation

不言
Release: 2023-03-23 08:52:02
Original
2152 people have browsed it

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

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!

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