To remove an HTML element from the DOM using JavaScript, you can use the remove() method, which is the simplest and most direct approach. Simply select the element and call .remove() on it:

document.getElementById("elementId").remove();

Alternatively, if you need to remove an element by referencing its parent, use the removeChild() method:

const element = document.getElementById("elementId");
element.parentNode.removeChild(element);

The remove() method is modern, widely supported, and removes the element itself along with all its content and event handlers. Use removeChild() when working with older environments or when you need more control over the removal process.

For removing elements by ID, the remove() method is preferred due to its simplicity and readability.

I know that augmenting native DOM functions isn't always the best or most popular solution, but this works fine for modern browsers.

Element.prototype.remove = function() {
    this.parentElement.removeChild(this);
}
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
    for(var i = this.length - 1; i >= 0; i--) {
        if(this[i] && this[i].parentElement) {
            this[i].parentElement.removeChild(this[i]);
        }
    }
}

And then you can remove elements like this

document.getElementById("my-element").remove();

or

document.getElementsByClassName("my-elements").remove();

Note: this solution doesn't work for IE 7 and below. For more info about extending the DOM read this article.

EDIT: Reviewing my answer in 2019, node.remove() has come to the rescue and can be used as follows (without the polyfill above):

document.getElementById("my-element").remove();

or

[...document.getElementsByClassName("my-elements")].map(n => n && n.remove());

These functions are available in all modern browsers (not IE). Read more on MDN.

Answer from Johan Dettmar on Stack Overflow
🌐
Sentry
sentry.io › sentry answers › javascript › how can i remove a specific item from an array?
How Can I Remove a Specific Item from an Array? | Sentry
If you want to remove an item from an array, you can use the pop() method to remove the last element or the shift() method to remove the first element.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-remove-an-element-from-a-javascript-array-removing-a-specific-item-in-js
How to Remove an Element from a JavaScript Array – Removing a Specific Item in JS
August 31, 2022 - The two arrays are concatenated together with concat to form an array that is similar to the starting one, but without a particular element. If you want to remove an element with a certain value, you can use Array.prototype.filter().
🌐
W3Schools
w3schools.com › jsref › met_element_remove.asp
HTML DOM Element remove Method
cssText getPropertyPriority() getPropertyValue() item() length parentRule removeProperty() setProperty() JS Conversion · ❮ Previous ❮ Element Object Reference Next ❯ · Remove an element from the document: const element = document.getElementById("demo"); element.remove(); Try it Yourself » ·
🌐
jQuery
api.jquery.com › remove
.remove() | jQuery API Documentation
Similar to .empty(), the .remove() method takes elements out of the DOM. Use .remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Element › remove
Element: remove() method - Web APIs | MDN
The Element.remove() method removes the element from its parent node. If it has no parent node, calling remove() does nothing. js · remove() None. None (undefined). html · <div id="div-01">Here is div-01</div> <div id="div-02">Here is div-02</div> <div id="div-03">Here is div-03</div> js ·
🌐
CoreUI
coreui.io › blog › how-to-remove-element-from-javascript-array
How to Remove Elements from a JavaScript Array · CoreUI
February 13, 2025 - One of the most popular ways to remove elements from an array in JavaScript is the splice method. This method modifies the original array directly. It takes at least two arguments (the start index and the number of elements to remove).
Find elsewhere
🌐
Mimo
mimo.org › glossary › javascript › removing-an-element
Learn how to Remove and Element in JavaScript
Removing an element from an array in JavaScript can be done in several ways depending on the position of the element or the condition you want to use. Here are some common methods: CAREER PATHFull-Stack Developer · Become a full-stack developer. Learn HTML, CSS, JavaScript, and React as well as NodeJS, Express, and SQL · Beginner friendly · COURSEJavaScript · Master the language of the web. Learn variables, functions, objects, and modern ES6+ features · Beginner friendly · JSX · Open in Mimo · Open in Mimo · Copy Code · // Remove the last element fruits.pop(); // Remove the first element fruits.shift(); // Remove a specific element by index fruits.splice(index, 1); // Remove an element based on a condition filtered = fruits.filter(item => item !== 'banana'); Each method affects the array differently.
🌐
DEV Community
dev.to › jsdevspace › 9-ways-to-remove-elements-from-arrays-in-javascript-4be6
9 Ways to Remove Elements from Arrays in JavaScript - DEV Community
August 6, 2024 - The splice(start, deleteCount, item1ToAdd, item2ToAdd, ...) method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › delete
delete - JavaScript | MDN
When the delete operator removes an array element, that element is no longer in the array. In the following example, trees[3] is removed with delete. js · const trees = ["redwood", "bay", "cedar", "oak", "maple"]; delete trees[3]; console.log(3 in trees); // false ·
🌐
Quora
quora.com › How-do-I-remove-an-element-from-the-DOM-using-Javascript
How to remove an element from the DOM using Javascript - Quora
Answer (1 of 25): ——— NOTE: 2/16/25 - I wrote the below answer about 7ish years ago, shortly after I joined Quora and I was still a relatively junior software engineer. It was also a time when jQuery was still a fairly dominant front end technology (it still among the most popular Javascript libr...
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › browser › remove dom element
Remove an element from the DOM using JavaScript - 30 seconds of code
July 4, 2024 - While it sounds simple, you can't simply ask an element to remove itself. Instead, you need to access its parent node and remove the element from there.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Node › removeChild
Node: removeChild() method - Web APIs | MDN
To remove a specified element without having to specify its parent node: js · const node = document.getElementById("child"); if (node.parentNode) { node.parentNode.removeChild(node); } To remove all children from an element: js · const element = document.getElementById("idOfParent"); while (element.firstChild) { element.removeChild(element.firstChild); } html ·
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › remove-elements-from-a-javascript-array
Remove Elements From a JavaScript Array - GeeksforGeeks
July 12, 2025 - Note : Please Read JavaScript Array Tutorial for complete understanding of JavaScript Array. The shift() method is used to remove and return the first element of the array and reduce the size of the original array by 1.
🌐
TutorialsPoint
tutorialspoint.com › remove-element-by-id-in-javascript
Remove element by id in JavaScript?
January 18, 2023 - An element or node can be removed using JavaScript's remove() method.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-remove-an-html-element-using-javascript
How to remove an HTML element using JavaScript ? - GeeksforGeeks
July 12, 2025 - JS Tutorial · Web Tutorial · ... element using JavaScript involves deleting it from the DOM, typically using methods like element.remove() or parentNode.removeChild()....
🌐
Devcamp
utahedu.devcamp.com › cts-2018 › guide › guide-removing-html-elements-javascript
Guide to Removing HTML Elements with JavaScript
So the first thing we're going to do is we're going to grab the messages so we'll say messages equals and then document.querySelectorAll because we want to grab all of these elements and then pass in the class. We know that they have a class of chatMsg so this is going to return a node list that we can work with. And so now all we have to do is iterate over them and remove them so I can say messages.forEach and then pass in a function.
🌐
Simple Dev
simpledev.io › lesson › remove-element-js-1
Client Challenge
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser