JavaScript Answers

How to Remove the Parent HTML Element Using JavaScript?

Spread the love

To remove the parent HTML element using JavaScript, we can use parentElement.remove method.

For instance, if we have the following HTML:

    hello world  

Then we can remove the p element’s parent, which is the div by writing:


We just select the p element with:


Then we call parentElement.remove() on it.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *