Replace text in node (v3)

Revision 3 of this benchmark created on


Preparation HTML

<div id="something">old text</div>

Test runner

Ready to run.

Testing in
TestOps/sec
innerHTML
document.getElementById("something").innerHTML = "new text";
ready
DOM traversing
var element = document.getElementById('something');

// removing everything inside the node
while (element.firstChild) {
    element.removeChild(element.firstChild);
}

// appending new text node
element.appendChild(document.createTextNode('new text'));
ready
textContent 1
document.getElementById("something").textContent = 'new text';
ready
textContent 2
var element = document.getElementById('something');

// removing child nodes
element.textContent = '';

// appending new text node
element.appendChild(document.createTextNode('new text'));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.