In Javascript , you can't delete the element directy if you want to delete the element , then first you have to find its parent element and delete it using remove() method .Because DOM ( Document Object Model ) doesn't support removing an element directly .
Example ->
<div id=" parent " >
<p id = "child" >I am user </p>
</div><br>
Code deleted with id ->
var child = document.getElementById(child);//get element
var div = document.getElementById(parent);//get parent element
parent.removeChild(child);
Now if you want to get parent element automatically , then you can use parentNode property of the child to find the parent property automatically .
var child = document.getElementById(child);//get element<br>
child.parentNode.removeChild(child);<br>//By using this you can automatically find the parent element
1 Comment(s)