innerHTML vs innerText vs nodeValue vs textContent (v13)

Revision 13 of this benchmark created on


Preparation HTML

<div id="divinputme">
</div>
<span id="spaninputme">
</span>
<script>
  var a = document.getElementById('divinputme'),
      b = document.getElementById('spaninputme'),
      s = '1,2,3,4';
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
innerText - div
a.innerText = s;
ready
innerText - span
b.innerText = s;
ready
innerHTML - div
a.innerHTML = s;
ready
innerHTML - span
b.innerHTML = s;
ready
nodeValue - div
 while (a.firstChild) {
a.removeChild(a.firstChild);
}
if (s!= null) {
      a.appendChild(document.createTextNode(s));
    }
ready
nodeValue - span
 while (b.firstChild) {
b.removeChild(b.firstChild);
}
if (s!= null) {
      b.appendChild(document.createTextNode(s));
}
ready
textContent - div
a.textContent = s;
ready
textContent - span
b.textContent = s;
ready

Revisions

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