jQuery append vs html

JavaScript performance comparison

Test case created by MarcinW

Preparation code

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

<div class="container"></div>
<script>
  var insertion = "<table><tr><td>1</td><td>2</td><td>3</td></tr></table>";
</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
innerHTML
$('.container').each(function() {
 this.innerHTML = "<table><tr><td>1</td><td>1</td><td>1</td></tr></table>";
})
pending…
html()
$('.container').html("<table><tr><td>2</td><td>2</td><td>2</td></tr></table>");
pending…
append()
$('.container').append("<table><tr><td>3</td><td>3</td><td>3</td></tr></table>");
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