Created
August 14, 2017 22:42
-
-
Save dnewcome/78a360891aa4609f5fe73c7682532884 to your computer and use it in GitHub Desktop.
Quick DOM element creation
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
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