Test name | Executions per second |
---|---|
innerHTML | 12756121.0 Ops/sec |
replaceChildren | 9138339.0 Ops/sec |
remove | 60391460.0 Ops/sec |
removeChild | 60791228.0 Ops/sec |
<div id="parent"></div>
const node = document.getElementById('parent');
const child = document.createElement('div')
child.textContent = 'some text'
for(var i = 0; i < 5000; i++) node.appendChild(child);
const node = document.getElementById('parent');
node.innerHTML = '';
const node = document.getElementById('parent');
node.replaceChildren();
const node = document.getElementById('parent');
while(node.firstChild) node.firstChild.remove()
const node = document.getElementById('parent');
while(node.firstChild) node.removeChild(node.firstChild)