JS appendChild usung js & jQuery - TerryLee7788/JS_test GitHub Wiki
Using Javascript...
var toAdd = document.createDocumentFragment();
for(var i=0; i < 11; i++){
var newDiv = document.createElement('div');
newDiv.id = 'r'+i;
newDiv.className = 'ansbox';
newDiv.innerHTML = 'hihi';
toAdd.appendChild(newDiv);
}
document.body.appendChild(toAdd); //組裝好後, 再一次加入DOM
Using jQuery...
var $myList = $("#list"),
list = "";
for(var i = 0; i < 10000; i++){
list += "<li>"+i+"</li>";
}
$myList.html(list); //組裝好後, 再一次加入DOM
// or
var array = [];
for(var i = 0; i < 10000; i++){
array[i] = "<li>"+i+"</li>";
}
$myList.html(array.join('')); //組裝好後, 再一次加入DOM