Last active
September 27, 2017 20:55
-
-
Save bcls/7fda8b4b7fbe8ae048768488c4ae172d to your computer and use it in GitHub Desktop.
append new content to HTML #javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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