jquery html() vs empty().append() performance

javascript, jquery, performance

Solution

In your code `$.empty().append()` was running faster because, your selector was wrong,

You should have used `var $test = $("#test");` instead of `var $test = $("test");` for comparision.

See the DEMO Here.

Problem

I have created a test case at http://jsperf.com/jquery-html-vs-empty-append-test to compare the performance of `$.html()` with `$.empty().append()`. I wondered that `.empty().append()` is faster. Can anyone explain this performance gap? Thanks.

Original source