innerHTML vs innerText vs nodeValue vs textContent

JavaScript performance comparison

Revision 21 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';
</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='test';
pending…
innerText - span
var test = b.innerText;
b.innerText='test';
pending…
innerHTML - div
var test = a.innerHTML;
a.innerHTML='test';
pending…
innerHTML - span
var test = b.innerHTML;
b.innerHTML='test';
pending…
nodeValue - div
var test = a.firstChild.nodeValue;
a.firstChild.nodeValue='test';
pending…
nodeValue - span
var test = b.firstChild.nodeValue;
b.firstChild.nodeValue='test';
pending…
textContent - div
var test = a.textContent;
a.textContent='test';
pending…
textContent - span
var test = b.textContent;
b.textContent='test';
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