innerHTML vs innerText vs nodeValue vs textContent (v22)

Revision 22 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';
  function someText() {
   var i=100, b=new Array(i), c='<b>1</b>23123123';
   for (i;i;i--) {b[i]=c;}
   return b.join('');
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
innerText - div
var test = a.innerText;
a.innerText=someText();
ready
innerText - span
var test = b.innerText;
b.innerText=someText();
ready
innerHTML - div
var test = a.innerHTML;
a.innerHTML=someText();
ready
innerHTML - span
var test = b.innerHTML;
b.innerHTML=someText();
ready
nodeValue - div
var test = a.firstChild.nodeValue;
a.firstChild.nodeValue=someText();
ready
nodeValue - span
var test = b.firstChild.nodeValue;
b.firstChild.nodeValue=someText();
ready
textContent - div
var test = a.textContent;
a.textContent=someText();
ready
textContent - span
var test = b.textContent;
b.textContent=someText();
ready

Revisions

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