Test name | Executions per second |
---|---|
innerHTML | 2066941.0 Ops/sec |
replaceChildren | 2109725.5 Ops/sec |
remove firstChild | 2936671.2 Ops/sec |
remove lastChild | 2941773.5 Ops/sec |
textContent | 1962089.1 Ops/sec |
remove and recreate root element | 188694.5 Ops/sec |
<div id="container"></div>
const container = document.querySelector('#container');
for (let i=0; i<300; i++)
container.appendChild(document.createElement('p'));
container.innerHTML ='';
container.replaceChildren()
while (container.firstChild)
container.removeChild(container.firstChild)
while (container.lastChild)
container.removeChild(container.lastChild)
container.textContent=''
const clone = container.cloneNode(false);
container.parentNode.replaceChild(clone, container);