innerHTML vs innerText vs nodeValue vs textContent

JavaScript performance comparison

Revision 40 of this test case created by

Preparation code

<div id="d"></div>
<span id="s"></span>
<script>
  var d = document.getElementById("d");
  var s = document.getElementById("s");
  var t = "abcd1234";
</script>
    

Preparation code output

<div id="d"></div> <span id="s"></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
d.innerText = t;
pending…
innerText - span
s.innerText = t;
pending…
innerHTML - div
d.innerHTML = t;
pending…
innerHTML - span
s.innerHTML = t;
pending…
childNodes[0].nodeValue - div
d.childNodes[0].nodeValue = t;
pending…
childNodes[0].nodeValue - span
s.childNodes[0].nodeValue = t;
pending…
firstChild.nodeValue - div
d.firstChild.nodeValue = t;
pending…
firstChild.nodeValue - span
s.firstChild.nodeValue = t
pending…
textContent - div
d.textContent = t;
pending…
textContent - span
s.textContent = t;
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