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

JavaScript performance comparison

Revision 13 of this test case created by

Preparation code

<script src="https://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

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

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
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.

0 Comments