innerHTML vs innerText vs nodeValue vs textContent

JavaScript performance comparison

Revision 19 of this test case created

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

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 = ''+(++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. Here’s a list of current revisions for this page:

0 comments

Add a comment