innerHTML vs innerText vs nodeValue vs textContent

JavaScript performance comparison

Revision 41 of this test case created by

Preparation code

<div id="d"></div>
<span id="s"></span>
<script>
  var p = document.querySelector('p.meta'); // Any visible element on that page that contains some text.
  var d = document.getElementById("d");
  var s = document.getElementById("s");
  var t = "abcd1234";
  console.log(p,d,s,t);
</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
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…
textContent - visible p
p.textContent = t;
pending…
innerText - visible p
p.innerText = t;
pending…
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…

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