.append VS .html VS [removed] performance

前端 未结 7 1651
星月不相逢
星月不相逢 2020-11-28 21:16

This site\'s run a test between the 3 different methods and it seems .html is the fastest, followed by .append. followed by .innerHTML

7条回答
  •  时光取名叫无心
    2020-11-28 21:40

    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

提交回复
热议问题