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

JavaScript performance comparison

Revision 13 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/jquery.min.js">
</script>
<div id="html">
</div>
<div id="text">
</div>
<div id="innerHTML">
</div>
<div id="innerText">
</div>
<script>
Benchmark.prototype.setup = function() {
    var text;
    for (var i = 0; i < 100; i++)
    text += "More more more more more more more more more more more";
};
</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
jQuery HTML
$("#html").html(text);
pending…
jQuery HTML cached
$("#html").html(text);
pending…
jQuery Text
$("#text").text(text);
pending…
jQuery Text cached
$("#html").text(text);
pending…
el.innerHTML
document.body.children[3].innerHTML = text;
pending…
el.innerHTML cached
document.body.children[3].innerHTML = text;
pending…
el.innerText
document.body.children[3].innerText = text;
pending…
el.innerText cached
document.body.children[3].innerText = 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