/html-dom /Basic
GitHub 4932★

Remove all children of a node

1. Empty the inner HTML (not recommended)

ele.innerHTML = '';

This method isn't recommended because it doesn't remove event handlers of child node. Hence, it might cause a memory leak if you are managing a big list of elements.

2. Remove child nodes

Remove its child node until it doesn't have any children.

while (node.firstChild) {
node.removeChild(node.firstChild);
}

See also

Follow me on and to get more useful contents.