Read innerHTML vs innerText vs nodeValue vs textContent

JavaScript performance comparison

Revision 18 of this test case created

Preparation code

<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>
  var a = document.getElementById('div'),
      b = document.getElementById('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
a.innerText="AAAAAAAAA";
pending…
innerText - span
b.innerText="AAAAAAAAA";
pending…
innerHTML - div
a.innerHTML="AAAAAAAAA";
pending…
innerHTML - span
b.innerHTML="AAAAAAAAA";
pending…
nodeValue - div
a.firstChild.nodeValue="AAAAAAAAA";
pending…
nodeValue - span
b.firstChild.nodeValue="AAAAAAAAA";
pending…
textContent - div
a.textContent="AAAAAAAAA";
pending…
textContent - span
b.textContent="AAAAAAAAA";
pending…
jQuery html() - div
$a.html("AAAAAAAAA");
pending…
jQuery html() - span
$b.html("AAAAAAAAA");
pending…
jQuery text() - div
$a.text("AAAAAAAAA");
pending…
jQuery text() - span
$b.text("AAAAAAAAA");
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