Skip to content

Instantly share code, notes, and snippets.

@guiseek
Created December 22, 2023 22:45
Show Gist options
  • Save guiseek/71f390f8c8826152691240aeacf4ffe2 to your computer and use it in GitHub Desktop.
Save guiseek/71f390f8c8826152691240aeacf4ffe2 to your computer and use it in GitHub Desktop.
create element
export const create = <K extends keyof HTMLElementTagNameMap>(
name: K,
attrs: Partial<HTMLElementTagNameMap[K]> = {},
...children: Element[]
): HTMLElementTagNameMap[K] => {
const el = document.createElement(name);
el.append(...children);
return Object.assign(el, attrs);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment