innerHTML vs innerText vs nodeValue vs textContent

JavaScript performance comparison

Revision 17 of this test case created by NAIF

Preparation code

<div id="divinputme">
</div>
<span id="spaninputme">
</span>
<script>
  var a = document.getElementById('divinputme'),
      b = document.getElementById('spaninputme');
</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 = 'div-innerText';
pending…
innerText - span
b.innerText = 'span-innerText';
pending…
innerHTML - div
a.innerHTML = 'div-innerHTML';
pending…
innerHTML - span
b.innerHTML = 'span-innerHTML';
pending…
nodeValue - div
a.firstChild.nodeValue = 'div-nodeValue';
pending…
nodeValue - span
b.firstChild.nodeValue = 'span-nodeValue';
pending…
textContent - div
a.textContent = 'div-textContent';
pending…
textContent - span
b.textContent = 'span-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