Skip to content

Instantly share code, notes, and snippets.

@bcls
Last active September 27, 2017 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcls/7fda8b4b7fbe8ae048768488c4ae172d to your computer and use it in GitHub Desktop.
Save bcls/7fda8b4b7fbe8ae048768488c4ae172d to your computer and use it in GitHub Desktop.
append new content to HTML #javascript
/**
* append new HTML elements to some existing one - efficiently
* @param {Object} htmlEl reference to the HTML element to append new HTML to
*/
function appendHTML(htmlEl) {
var i = 0, el, fragment = document.createDocumentFragment();
while (i < 200) {
el = document.createElement('li');
el.innerText = 'This is my list item number ' + i;
fragment.appendChild(el);
i++; }
htmlEl.appendChild(fragment);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment