Skip to content

Instantly share code, notes, and snippets.

@misebox
Last active June 9, 2021 09:49
Show Gist options
  • Save misebox/994cf6070bb6450d8e76ecb6839c5131 to your computer and use it in GitHub Desktop.
Save misebox/994cf6070bb6450d8e76ecb6839c5131 to your computer and use it in GitHub Desktop.
Shorthand function for document.createElement
export default (function(doc) {
function element(elmName, attrs={}) {
const elm = doc.createElement(elmName);
Object.keys(attrs).map(k => elm.setAttribute(k,attrs[k]));
return elm;
}
function divAs(className, attrs={}) {
return element('div', {class: className, ...attrs});
}
return {
element,
divAs,
};
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment