innerHTML vs innerText vs nodeValue vs textContent

JavaScript performance comparison

Revision 19 of this test case created by

Preparation code

<div id="divinputme" style="position:absolute">
</div>
<span id="spaninputme" style="position:absolute">
</span>
<script>
  var a = document.getElementById('divinputme'),
      b = document.getElementById('spaninputme');
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var i = 0;

};
</script>

Preparation code output

<div id="divinputme" style="position:absolute"> </div> <span id="spaninputme" style="position:absolute"> </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
a.innerText = ''+(++i);
pending…
innerText - span
b.innerText = ''+(++i);
pending…
innerHTML - div
a.innerHTML = ''+(++i);
pending…
innerHTML - span
b.innerHTML = ''+(++i);
pending…
nodeValue - div
a.firstChild.nodeValue = ''+(++i);
pending…
nodeValue - span
b.firstChild.nodeValue = ''+(++i);
pending…
textContent - div
a.textContent = ''+(++i);
pending…
textContent - span
b.textContent = ''+(++i);
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