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

Benchmark created on


Preparation HTML

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

Setup

var html = '<ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>';
    
    $('body').append($('#test-wrapper'));

Test runner

Ready to run.

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

Revisions

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