This article illustrates the method of deleting a specified HTML element using native JavaScript implementations. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title> Cloud-dwelling community </title>
<style>
#content {
width:200px;
height:20px;
color:red;
}
</style>
<script>
Window.onload=function () {
var Obt=document.getelementbyid ("BT");
var Odiv=document.getelementbyid ("content");
Obt.onclick=function () {
Odiv.parentNode.removeChild (ODIV);
}
}
</script>
<body>
<div id= "Content" > cloud-Habitat Community </div>
<input type= "button" id= "BT" value= "viewing effect"/>
</body>
In native JavaScript, there is no single way to delete the element itself, and if you want to remove the specified child element by deleting the RemoveChild () method from the parent node, the code is simpler, and you can refer to the relevant information for your interested friends.
I hope this article will help you with your JavaScript based Web programming.