Test name | Executions per second |
---|---|
innerHTML | 12756078.0 Ops/sec |
replaceChildren | 9235688.0 Ops/sec |
remove | 61576136.0 Ops/sec |
removeChild | 61379340.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)