Files
30-seconds-of-code/snippets/removeElement.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

517 B

title, tags, author, cover, firstSeen, lastUpdated
title tags author cover firstSeen lastUpdated
Remove DOM element browser chalarangelo by-the-lighthouse 2021-01-07T00:20:34+02:00 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