innerHTML vs innerText vs nodeValue vs textContent

JavaScript performance comparison

Revision 23 of this test case created by

Preparation code

<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=5, b=new Array(i), c='<b>1</b><div style="display:none">23123123</div>';
   for (i;i;i--) {b[i]=c;}
b.push(Math.random());
   return b.join('');
  }
</script>
    

Preparation code output

<div id="divinputme"> 123 123 123 </div> <span id="spaninputme"> 123 123 123 </span>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
innerText - div
var test = a.innerText;
a.innerText=someText();
pending…
innerText - span
var test = b.innerText;
b.innerText=someText();
pending…
innerHTML - div
var test = a.innerHTML;
a.innerHTML=someText();
pending…
innerHTML - span
var test = b.innerHTML;
b.innerHTML=someText();
pending…
nodeValue - div
var test = a.firstChild.nodeValue;
a.firstChild.nodeValue=someText();
pending…
nodeValue - span
var test = b.firstChild.nodeValue;
b.firstChild.nodeValue=someText();
pending…
textContent - div
var test = a.textContent;
a.textContent=someText();
pending…
textContent - span
var test = b.textContent;
b.textContent=someText();
pending…

Compare results of other browsers

Revisions

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

0 Comments

123 123 123
123 123 123