| 8 | } |
| 9 | |
| 10 | export function createElement(name: string, opts?: IHTMLElementOption, ...children: HTMLElement[]): HTMLElement { |
| 11 | const el = document.createElement(name) |
| 12 | if (opts) { |
| 13 | if (opts.attrs) { |
| 14 | for (const key in opts.attrs) { el.setAttribute(key, opts.attrs[key]) } |
| 15 | } |
| 16 | if (opts.class) { |
| 17 | el.setAttribute('class', opts.class) |
| 18 | } |
| 19 | if (opts.on) { |
| 20 | for (const ev in opts.on) { el.addEventListener(ev, opts.on[ev]) } |
| 21 | } |
| 22 | if (opts.text) { |
| 23 | el.innerText = opts.text |
| 24 | } |
| 25 | } |
| 26 | el.append(...children) |
| 27 | return el |
| 28 | } |
| 29 | |
| 30 | export function $div(opts?: IHTMLElementOption, ...children: HTMLElement[]): HTMLElement { |
| 31 | return createElement('div', opts, ...children) |