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