innerHTML vs innerText vs nodeValue vs textContent

JavaScript performance comparison

Revision 45 of this test case created by

Preparation code

<div id="divinputme">1</div>
<script>
  var a = document.getElementById('divinputme'),
      s = 2;
</script>
    

Preparation code output

<div id="divinputme">1</div>

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 = s;
pending…
innerHTML - div
a.innerHTML = s;
pending…
nodeValue - div
if(a.childNodes.length===0){
  a.textContent = " ";
}
a.firstChild.nodeValue = s;
pending…
textContent - div
a.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.

0 Comments

1