jquery html() vs empty().append() performance
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.
Use the selector correctly in jquery,
$('#test').html('Example');
will be faster obviously than
$.empty().append();
But
$('test')
will search the DOM for an element with tag name 'TEST'.
In this section you should use innerHTML
. because this is native Javascript.
see the http://jsperf.com/jquery-append-vs-html-list-performance/27
链接地址: http://www.djcxy.com/p/73870.html上一篇: 管道从交互式命令输出到更少