remove method

The remove method allows you to remove an element. It applies to the element to be removed.

Syntax

javascriptelement.remove();

Example

Let's delete the #elem paragraph:

html<div id="parent">
  <p id="elem">elem 1</p>
  <p>elem 2</p>
</div>
javascriptlet elem = document.querySelector('#elem');
elem.remove();

The code execution result:

html<div id="parent">
  <p>elem 2</p>
</div>

See also

  • the removeChild method
    that can be used to remove an element