jQuery.html() vs jQuery.text() vs el.innerHTML vs el.innerText

JavaScript performance comparison

Revision 9 of this test case created

Info

Testing DOM vs native element content with append and single substitutions.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

<div id="html"></div>
<div id="text"></div>
<div id="innerText"></div>
<div id="innerHTML"></div>

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
jQuery HTML
var o=$("#html");
for (var i = 0; i < 50; i++) {
  o.html("More text");
}
pending…
jQuery Text
var o=$("#text");
for (var i = 0; i < 50; i++) {
  o.text("More text");
}
pending…
el.innerText
var o=$("#innerText").get(0);
for (var i = 0; i < 50; i++) {
  o.innerText = "More text";
}
pending…
el.innerHTML
var o=$("#innerHTML").get(0);
for (var i = 0; i < 50; i++) {
  o.innerHTML = "More text";
}
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