Rename js snippets
This commit is contained in:
23
snippets/js/s/remove-dom-element.md
Normal file
23
snippets/js/s/remove-dom-element.md
Normal file
@ -0,0 +1,23 @@
|
||||
---
|
||||
title: Remove DOM element
|
||||
type: snippet
|
||||
language: javascript
|
||||
tags: [browser]
|
||||
author: chalarangelo
|
||||
cover: by-the-lighthouse
|
||||
dateModified: 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
|
||||
```
|
||||
Reference in New Issue
Block a user