JavaScript, Browser

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);
// Removes #my-element from the DOM

Recommended snippets

  • renderElement

    JavaScript, Browser

    Renders the given DOM tree in the specified DOM element.

  • off

    JavaScript, Browser

    Removes an event listener from an element.

  • removeClass

    JavaScript, Browser

    Removes a class from an HTML element.