Read innerHTML vs innerText vs nodeValue vs textContent

JavaScript performance comparison

Revision 2 of this test case created by Rob

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/mootools/1.3/mootools-yui-compressed.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="div">1,2,3,4</div>
<span id="span">1,2,3,4</span>
<script>
  jQuery.noConflict();
  var a = document.getElementById('div'),
      b = document.getElementById('span'),
      $a = jQuery('div'),
      $b = jQuery('span'),
      $$a = $$('div'),
      $$b = $$('span'),
      s;
</script>

Preparation code output

1,2,3,4
1,2,3,4

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
s = a.innerText;
pending…
innerText - span
s = b.innerText;
pending…
innerHTML - div
s = a.innerHTML;
pending…
innerHTML - span
s = b.innerHTML;
pending…
nodeValue - div
s = a.firstChild.nodeValue;
pending…
nodeValue - span
s = b.firstChild.nodeValue;
pending…
textContent - div
s = a.textContent;
pending…
textContent - span
s = b.textContent;
pending…
jQuery text - div
s = $a.text();
pending…
jQuery text - span
s = $b.text();
pending…
jQuery html - div
s = $a.html();
pending…
jQuery html - span
s = $b.html();
pending…
MooTools text - div
s = $$a.get('text');
pending…
MooTools text - span
s = $$b.get('text');
pending…
MooTools html - div
s = $$a.get('html');
pending…
MooTools html - span
s = $$b.get('html');
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