Skip to content

Instantly share code, notes, and snippets.

@earthboundkid
Last active June 22, 2020 14:44
Show Gist options
  • Save earthboundkid/45c0b8394f28b2ee3662edfeb80d29ee to your computer and use it in GitHub Desktop.
Save earthboundkid/45c0b8394f28b2ee3662edfeb80d29ee to your computer and use it in GitHub Desktop.
export default function createElement(
tag = "div",
{ classList = [], attrs = {}, children = [], ...props } = {}
) {
let el = document.createElement(tag);
for (let c of classList) {
el.classList.add(c);
}
for (let attr in attrs) {
el.setAttribute(attr, attrs[attr]);
}
Object.assign(el, props);
el.append(...children);
return el;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment