MCPcopy
hub / github.com/tinyplex/tinybase / createElement

Function createElement

site/js/common/common.ts:34–48  ·  view source on GitHub ↗
(
  tagName: string,
  parent?: HTMLElement | null,
  attributes: Record<string, string> = {},
  text?: string,
)

Source from the content-addressed store, hash-verified

32 doc.getElementById(id) as HTMLElement;
33
34export const createElement = (
35 tagName: string,
36 parent?: HTMLElement | null,
37 attributes: Record<string, string> = {},
38 text?: string,
39): HTMLElement => {
40 const element = doc.createElement(tagName);
41 Object.entries(attributes).forEach((attribute) =>
42 element.setAttribute(...attribute),
43 );
44 if (text != null) {
45 element.innerText = text;
46 }
47 return parent != null ? parent.appendChild(element) : element;
48};
49
50export const addClass = (element: HTMLElement, add: string): void =>
51 element.classList.add(add);

Callers 6

searchLoadFunction · 0.90
populateResultsFunction · 0.90
addHiddenInputFunction · 0.85
addStackblitzFunction · 0.85
updateNavFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…