To remove the parent HTML element using JavaScript, we can use parentElement.remove
method.
For instance, if we have the following HTML:
<div>
<p>
hello world
</p>
</div>
Then we can remove the p element’s parent, which is the div by writing:
document.querySelector('p').parentElement.remove();
We just select the p element with:
document.querySelector('p')
Then we call parentElement.remove()
on it.