Skip to content

Instantly share code, notes, and snippets.

@pdaug
Created May 22, 2024 20:43
Show Gist options
  • Save pdaug/d0906e3d031bff59f307e67dd3491545 to your computer and use it in GitHub Desktop.
Save pdaug/d0906e3d031bff59f307e67dd3491545 to your computer and use it in GitHub Desktop.
const createElement = function ({ className = '', id = '', tag = 'div', name = '' }) {
const element = document.createElement(tag);
if (className) {
element.classList.add(className);
}
if (name) {
element.setAttribute('name', name);
}
if (id) {
element.setAttribute('id', id);
}
return element;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment