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.
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.
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.
In this section you should use innerHTML. because this is native Javascript.
see the http://jsperf.com/jquery-append-vs-html-list-performance/27