MCPcopy Create free account
hub / github.com/JavaCS3/xterm-player / createElement

Function createElement

src/ui/DomHelper.ts:10–28  ·  view source on GitHub ↗
(name: string, opts?: IHTMLElementOption, ...children: HTMLElement[])

Source from the content-addressed store, hash-verified

8}
9
10export 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
30export function $div(opts?: IHTMLElementOption, ...children: HTMLElement[]): HTMLElement {
31 return createElement('div', opts, ...children)

Callers 2

$divFunction · 0.85
$spanFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected