Web APIs
Element.remove()
remove detaches an element from its parent. A JavaScript variable can still refer to the detached node. replaceChildren replaces all children with supplied nodes or strings.
Formal Syntax & Structure
javascript syntaxjavascript
element.remove()Return Value
undefined
No result value.
Working Example
Example Snippetjavascript
const r=document.createElement("div"),p=document.createElement("p");p.textContent="old";r.append(p);p.remove();r.replaceChildren("new");console.log(p.textContent,r.textContent,p.parentNode===null);