Javascript remo...LOGIN

Javascript removeChild(): delete node

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

Syntax:
parent.removeChild(thisNode)
Parameter description:

QQ截图20161013112729.png

For example, delete id=" demo" node statement is:

var thisNode=document.getElementById("demo");
thisNode.parentNode.removeNode(thisNode);

For example, delete the node:

<div id="demo">
    <div id="thisNode">点击删除我</div>
</div>
<script type="text/javascript">
document.getElementById("thisNode").onclick=function(){
    this.parentNode.removeChild(this);
}
</script>

It can be seen that although Javascript only provides one method to delete nodes, it is enough.

Next Section
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <div id="demo"> <div id="thisNode">点击删除我</div> </div> <script type="text/javascript"> document.getElementById("thisNode").onclick=function(){ this.parentNode.removeChild(this); } </script> </head> <body> </body> </html>
submitReset Code
ChapterCourseware