Files
30-seconds-of-code/snippets/js/s/remove-dom-element.md
Angelos Chalaris 9d032ce05e Rename js snippets
2023-05-19 20:23:47 +03:00

518 B

title, type, language, tags, author, cover, dateModified
title type language tags author cover dateModified
Remove DOM element snippet javascript
browser
chalarangelo by-the-lighthouse 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.
const removeElement = el => el.parentNode.removeChild(el);
removeElement(document.querySelector('#my-element'));
// Removes #my-element from the DOM