Web APIs

Element.remove()

Try the free JavaScript compiler

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);
JavaScript Reference