innerHTML vs innerText vs nodeValue

JavaScript performance comparison

Revision 28 of this test case created by Ojle Nenpleto

Preparation code

<div id="divinputme">
</div>
<span id="spaninputme">
</span>
<script>
  var a = document.getElementById('divinputme'),
      b = document.getElementById('spaninputme');
  s = '1,2,3,4';
</script>
<script>
Benchmark.prototype.setup = function() {
    document.getElementById('divinputme').innerHTML = '';
    document.getElementById('spaninputme').innerHTML = '';
};

Benchmark.prototype.teardown = function() {
    document.getElementById('divinputme').innerHTML = '';
    document.getElementById('spaninputme').innerHTML = '';
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
innerText - div
a.innerText = s;
pending…
innerHTML - div
a.innerHTML = s;
pending…
nodeValue - div
a.nodeValue = s;
pending…
textnode - div
a.appendChild(document.createTextNode(s))
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. Here’s a list of current revisions for this page:

0 comments

Add a comment