Files
tiny-worlds/web/dom.mjs
T

15 lines
630 B
JavaScript

// web/dom.mjs -- the two DOM helpers everything else builds on.
/** The id is static in index.html; a miss is a runtime crash by
* design (fail loud, never render a half-view). @param {string} id @returns {HTMLElement} */
export const $ = (id) => /** @type {HTMLElement} */ (document.getElementById(id));
/** One element, class and text in the common shape.
* @param {string} tag @param {?string} [cls] @param {?string} [text] @returns {HTMLElement} */
export function el(tag, cls, text) {
const e = document.createElement(tag);
if (cls) e.className = cls;
if (text !== undefined) e.textContent = text;
return e;
}