Skip to content

Instantly share code, notes, and snippets.

@dnewcome
Created August 14, 2017 22:42
Show Gist options
  • Save dnewcome/78a360891aa4609f5fe73c7682532884 to your computer and use it in GitHub Desktop.
Save dnewcome/78a360891aa4609f5fe73c7682532884 to your computer and use it in GitHub Desktop.
Quick DOM element creation
function elcreate (tag, styles = {}, attrs = {}, children=[]) {
let el = document.createElement(tag);
Object.keys(styles).forEach((item) => {
el.style[item] = styles[item];
});
Object.keys(attrs).forEach((item) => {
el[item] = attrs[item];
});
children.forEach((item)=>{
el.appendChild(elcreate(item));
});
return el;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment