This site\'s run a test between the 3 different methods and it seems .html
is the fastest, followed by .append
. followed by .innerHTML
I think the innerHTML is faster with suggesstion @Brat.
And on creating loop and appending string should be good on using variable first. It is make your performance more good.
good code:
var html = '';
for (var i = 0; i < len; i++) {
html += 'Test ' + i + '';
};
$('#list').append(html);
not efficient code:
for (var i = 0; i < len; i++) {
var html = 'Test ' + i + '';
$('#list').append(html);
}
for example: http://jsben.ch/#/yDvKH