Files
ui-lib/lib/functions.js
T
2026-11-18 10:14:21 +08:00

20 lines
573 B
JavaScript

/**
* @template {keyof HTMLElementTagNameMap} K
* @param {K} tagName
* @param {string | ((e: HTMLElementTagNameMap[K]) => void) | null} [init]
* @param {...(string | Node)} children
* @returns {HTMLElementTagNameMap[K]}
*/
export function createElement(tagName, init, ...children) {
const element = document.createElement(tagName);
if (typeof init === 'function') {
init(element);
} else if (init != null) {
element.className = init;
}
if (children.length > 0) {
element.append(...children);
}
return element;
}