Test name | Executions per second |
---|---|
using range | 6769.2 Ops/sec |
using insertAdjacentHTML | 6662.4 Ops/sec |
const targetElem = document.createElement( 'DIV' );
targetElem.id = 'target';
targetElem.innerHTML = `
<div>
<span>Child 1</span>
</div>
<div>
<span>Child 2</span>
</div>
<div>
<span>Child 3</span>
</div>
`;
document.body.appendChild( targetElem );
const range = new Range();
const frag = range.createContextualFragment("<h1>Some header</h1>")
document.getElementById("target").appendChild(frag);
document.getElementById("target").insertAdjacentHTML("afterbegin", "<h1>Some content</h1>")