Created
December 22, 2023 22:45
-
-
Save guiseek/71f390f8c8826152691240aeacf4ffe2 to your computer and use it in GitHub Desktop.
create element
This file contains hidden or 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
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