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

JavaScript performance comparison

Revision 5 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.7.2/jquery.min.js"></script>

<div id="html"></div>
<div id="text"></div>
<div id="innerText"></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
for (var i = 0; i < 50; i++) {
  document.body.children[3].innerText = "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