Files
30-seconds-of-code/snippets/remove-element.md
Angelos Chalaris 61200d90c4 Kebab file names
2023-04-27 21:58:35 +03:00

23 lines
517 B
Markdown

---
title: Remove DOM element
tags: browser
author: chalarangelo
cover: by-the-lighthouse
firstSeen: 2021-01-07T00:20:34+02:00
lastUpdated: 2021-01-07T00:20:34+02:00
---
Removes an element from the DOM.
- Use `Node.parentNode` to get the given element's parent node.
- Use `Node.removeChild()` to remove the given element from its parent node.
```js
const removeElement = el => el.parentNode.removeChild(el);
```
```js
removeElement(document.querySelector('#my-element'));
// Removes #my-element from the DOM
```