/html-dom /Basic
GitHub 4932★

Unwrap an element

Remove the ele element except its children:

// Get the parent node
const parent = ele.parentNode;

// Move all children node to the parent
while (ele.firstChild) {
parent.insertBefore(ele.firstChild, ele);
}

// `ele` becomes an empty element
// Remove it from the parent
parent.removeChild(ele);

See also

Follow me on and to get more useful contents.