JavaScript’s Element.remove() method removes the Element from the DOM (Document Object Model).

Syntax

Element.remove();

Parameters

None.

Return value

The remove() method does not have a return value, which means that the method implicitly returns undefined.

Examples

Here is an example of using the JavaScript remove() method.

Suppose we have the following HTML elements:

<p>This is an example of programming with <span>JavaScript</span>.</p>

What can we do if we want to remove the p element with JavaScript?

Well, we can select the element with the querySelector() method and use the remove() method:

let p = document.querySelector('p');
p.remove();

The remove() method removes both the p and span elements.

Browser compatibility

Chrome
Edge
Firefox
Internet Explorer
Opera
Safari
Chrome (Android)
Firefox (Android)
Opera (Android)
Safari (iOS)
Samsung Internet
WebView (Android)
remove() 24 12 23 15 7 25 23 14 7 1.5 4.4