CRELT is a minimalist and tiny JavaScript utility designed for the efficient creation of DOM elements. It simplifies the process of programmatically constructing HTML structures by providing a single function that accepts a tag name (or existing DOM element), an optional attributes object, and any number of child nodes. Attributes specified as strings are set via `setAttribute`, while non-string values (like functions for event handlers) are assigned as direct properties. Children can be strings (for text nodes), DOM nodes, or arrays of children. The library is currently stable at version 1.0.6, indicating a mature and likely infrequent release cadence. Its key differentiator is its small footprint and direct, unopinionated approach to DOM manipulation, serving as a lightweight alternative to JSX or more complex templating engines for scenarios requiring programmatic DOM construction.
npm install creltVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating a hierarchical DOM structure using `crelt`, including dynamic attributes, event handlers, and different types of children (strings, other `crelt`-generated elements, and arrays of elements).
Always pass functions (or other non-string types) for properties that expect them (e.g., `onclick: myHandler`). Use string values only for standard HTML attributes.
Be mindful of explicitly passing `null` or `undefined`. If conditionally adding children, ensure the condition correctly resolves to a valid element or nothing, e.g., `condition ? crelt('div', 'content') : null`.To create multiple top-level elements, make separate `crelt` calls. To group multiple elements into a fragment before appending, you can manually create a `DocumentFragment` and then append `crelt`-generated elements to it.
Use `import crelt from 'crelt';` for ES Modules or `const crelt = require('crelt');` for CommonJS, as `crelt` exports a single default function.Ensure `import crelt from 'crelt';` (or the equivalent CommonJS `require`) is at the top of your module or script file where `crelt` is being used.
Verify that the first argument passed to `crelt` is always a valid HTML tag name string (e.g., `'div'`, `'button'`) or a pre-existing DOM element.
No dependency data recorded yet.