jQuery appending an array of elements

后端 未结 9 728
星月不相逢
星月不相逢 2020-12-13 23:34

For the purpose of this question lets say we need to append() 1000 objects to the body element.

You could go about it like this:

         


        
9条回答
  •  别那么骄傲
    2020-12-13 23:53

    I would use native Javascript, normally much faster:

    var el = document.getElementById('the_container_id');
    var aux;
    for(x = 0; x < 1000; x++) {
        aux = document.createElement('div');
        aux.innerHTML = x;
        el.appendChild(aux);
    }
    

    EDIT:

    There you go a jsfiddle with different options implemented. The @jackwander's solution is, clearly, the most effective one.

提交回复
热议问题