Skip to content

Instantly share code, notes, and snippets.

@dhwang
Created June 10, 2019 18:43
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 dhwang/339fedaf10e8bd862dca99aded537465 to your computer and use it in GitHub Desktop.
Save dhwang/339fedaf10e8bd862dca99aded537465 to your computer and use it in GitHub Desktop.
appendFragment
function appendFragment(element, data) {
var tagMap = { ul: 'li', table: 'tr', tr: 'td' };
var tag = tagMap[element.tagName] || 'li';
var fragment = document.createDocumentFragment();
data.forEach(function(item) {
var li = document.createElement(tag);
li.textContent = item;
fragment.appendChild(li);
});
element.appendNode(fragement);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment