5000 element innerHTML with string concatenation | var innerHTMLstr = '<div>';
for (var i = 0; i < 5000; i++) {
innerHTMLstr += '<div><span class="foo" style="color: red">' + i + '</span></div>';
}
innerHTMLstr += '</div>';
document.getElementById('container').innerHTML = innerHTMLstr;
document.title = document.getElementById('container').innerHTML;
| ready |
5000 element innerHTML without string concatenation | var innerHTMLarr = ['<div>'];
for (var i = 0; i < 5000; i++) {
innerHTMLarr.push('<div><span class="foo" style="color: red">');
innerHTMLarr.push(i);
innerHTMLarr.push('</span></div>');
}
innerHTMLarr.push('</div>');
document.getElementById('container').innerHTML = innerHTMLarr.join('');
document.title = document.getElementById('container').innerHTML;
| ready |
5000 element createElement added in sequence | var container = document.getElementById('container');
var outerdiv = document.createElement('div');
container.appendChild(outerdiv);
for (var i = 0; i < 5000; i++) {
var div = document.createElement('div');
var span = document.createElement('span');
span.setAttribute("class", "foo");
span.setAttribute("style", "color: red");
span.appendChild(document.createTextNode(i));
div.appendChild(span);
outerdiv.appendChild(div);
}
document.title = document.getElementById('container').innerHTML;
| ready |
5000 element createElement bulk add | var container = document.getElementById('container');
var outerdiv = document.createElement('div');
for (var i = 0; i < 5000; i++) {
var div = document.createElement('div');
var span = document.createElement('span');
span.setAttribute("class", "foo");
span.setAttribute("style", "color: red");
span.appendChild(document.createTextNode(i));
div.appendChild(span);
outerdiv.appendChild(div);
}
container.appendChild(outerdiv);
document.title = document.getElementById('container').innerHTML;
| ready |
5000 element createElement parse each piece | var root, target;
target = document.getElementById('container');
for (var i = 0; i < 5000; i++) {
root = document.createElement('div');
root.innerHTML = '<div><span class="foo" style="color: red">' + i + '</span></div>';
target.appendChild (root);
}
document.title = target.innerHTML;
| ready |