jQuery.html() vs jQuery.append() vs jQuery.prepend() (v15)

Revision 15 of this benchmark created on


Preparation HTML

<script src="//code.jquery.com/jquery-git2.min.js"></script>
<div id="test-wrapper"><span id="text">text</span></div>

Setup

var hvar = '<li>Item 4</li>';
    var html = '<ul><li>Item 1</li><li>Item 2</li><li>Item 3</li>' + hvar + '</ul>';

Teardown


    $('#test-wrapper').empty();
  

Test runner

Ready to run.

Testing in
TestOps/sec
html
$('#test-wrapper').html(html);
ready
append
$('#test-wrapper').append(html);
ready
empty+append
$('#test-wrapper').empty().append(html);
ready
prepend
$('#test-wrapper').prepend(html);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.