Home >Backend Development >PHP Tutorial >Example of JS implementation of DOM deletion node operation
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('di'); 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 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!