innerHTML vs innerText vs nodeValue vs textContent

JavaScript performance comparison

Revision 13 of this test case created

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>

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…
innerText - span
b.innerText = s;
pending…
innerHTML - div
a.innerHTML = s;
pending…
innerHTML - span
b.innerHTML = s;
pending…
nodeValue - div
 while (a.firstChild) {
a.removeChild(a.firstChild);
}
if (s!= null) {
      a.appendChild(document.createTextNode(s));
    }
pending…
nodeValue - span
 while (b.firstChild) {
b.removeChild(b.firstChild);
}
if (s!= null) {
      b.appendChild(document.createTextNode(s));
}
pending…
textContent - div
a.textContent = s;
pending…
textContent - span
b.textContent = 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