This article describes the method of deleting a specified html element using native javascript. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows: <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="//www.VeVB.COM/" />
<title>Wulin.com</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>
</head>
<body>
<div id="content">Wulin.com</div>
<input type="button" id="bt" value="View effect"/>
</body>
</html>
In native javascript, there is currently no method that can delete the element itself. If you want to delete it, you can delete the specified child element by using the removeChild() method of the parent node. The code is relatively simple. I won't introduce it here. Interested friends can refer to the relevant information.
I hope that the description in this article will be helpful to everyone's web programming based on javascript.