UNPKG

@qntm-code/utils

Version:

A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.

14 lines (13 loc) 453 B
/** * Creates a dom element of a given type, applies any supplied styles, and adds to the body element (if not disbaled) */ export function createElement(type, styles, addToDom = true) { const element = document.createElement(type); if (styles) { Object.entries(styles).forEach(([property, value]) => (element.style[property] = value)); } if (addToDom) { document.body.appendChild(element); } return element; }