Files
30-seconds-of-code/snippets/removeElement.md
Isabelle Viktoria Maciohsek 27c168ce55 Bake date into snippets
2021-06-13 13:55:00 +03:00

481 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
removeElement browser,beginner 2021-01-07T00:20:34+02:00 2021-01-07T00:20:34+02:00

Removes an element from the DOM.

  • Use Element.parentNode to get the given element's parent node.
  • Use Element.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