179 of 264 menu

remove method

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

Syntax

element.remove();

Example

Let's delete the #elem paragraph:

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

The code execution result:

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

See also

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