If you really want to get every single piece of performance out of your code, you should only use document.getElementById once and modify the document once. Also, Node.prototype.cloneNode seems to be a bit faster than Document.prototype.createElement.
var nodeHolder = document.getElementById("nodeHolder"),
fragment = document.createDocumentFragment(), // Create a fragment to avoid repetitive manipulation of the document
templateNode = document.createElement("div"), // Create a template div
el,
i;
for (i = 1; i < 1001; i += 1) {
// Clone the node instead of using createElement
el = templateNode.cloneNode();
el.appendChild(document.createTextNode("Node " + i));
// Append to the fragment
fragment.appendChild(el);
}
// Append the fragment to the holder
nodeHolder.appendChild(fragment);
If I missed something, feel free to tell me.
Edits:
"Shift the start and end value of i by 1 to eliminate the (i + 1)" – Xotic750
iby 1. MovegetElementByIdoutside of the loop, only need to get it's reference once. Build the elements in afragment, then update the DOM when the loop is finished.