innerHTML vs innerText vs nodeValue vs textContent (v21)

Revision 21 of this benchmark created on


Preparation HTML

<div id="divinputme">
123 123 123
</div>
<span id="spaninputme">
123 123 123
</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
var test = a.innerText;
a.innerText='test';
ready
innerText - span
var test = b.innerText;
b.innerText='test';
ready
innerHTML - div
var test = a.innerHTML;
a.innerHTML='test';
ready
innerHTML - span
var test = b.innerHTML;
b.innerHTML='test';
ready
nodeValue - div
var test = a.firstChild.nodeValue;
a.firstChild.nodeValue='test';
ready
nodeValue - span
var test = b.firstChild.nodeValue;
b.firstChild.nodeValue='test';
ready
textContent - div
var test = a.textContent;
a.textContent='test';
ready
textContent - span
var test = b.textContent;
b.textContent='test';
ready

Revisions

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