innerHTML vs innerText vs nodeValue vs textContent

JavaScript performance comparison

Revision 20 of this test case created

Preparation code

<div id="divinputme">
123 123 123
</div>
<span id="spaninputme">
123 123 123
</span>
<script>
  var a = document.getElementById('divinputme'),
      b = document.getElementById('spaninputme'),
      s = '1,2,3,4';
</script>

Preparation code output

123 123 123
123 123 123

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
var test = a.innerText;
pending…
innerText - span
var test = b.innerText;
pending…
innerHTML - div
var test = a.innerHTML;
pending…
innerHTML - span
var test = b.innerHTML;
pending…
nodeValue - div
var test = a.firstChild.nodeValue;
pending…
nodeValue - span
var test = b.firstChild.nodeValue;
pending…
textContent - div
var test = a.textContent;
pending…
textContent - span
var test = b.textContent;
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