π dotElement is a lightweight utility similar to React.createElement, but for vanilla JavaScript. It allows you to create and manage DOM elements efficiently with a JSX-like approach.
- π JSX-like API for creating DOM elements.
- π¨ Styling Support: Apply styles using
classNameor an inlinestyleobject (like:{backgroundColor: "red"}). - π Event Listeners: Add event handlers just like in React (
onClick,onChange, etc.). - π Lightweight & fast.
- π Fully TypeScript-supported.
Install via npm or pnpm:
npm install dotElementOr using pnpm:
pnpm add dotElementimport { createElement } from "dotElement";
document.body.appendChild(
createElement("button", {
className: "btn-primary",
style: { backgroundColor: "blue", color: "white", padding: "10px" },
onClick: () => alert("Button Clicked!"),
}, "Click Me!")
);const container = createElement("div", { className: "container" },
createElement("h1", {}, "Hello, dotElement!"),
createElement("p", {}, "This is a lightweight JSX alternative for vanilla JS."),
createElement("button", {
onClick: () => alert("Clicked!"),
style: { padding: "10px", backgroundColor: "green", color: "white" }
}, "Click Me")
);
document.body.appendChild(container);| Parameter | Type | Description |
|---|---|---|
tagName |
string |
The HTML tag name (e.g., "div", "span"). |
props |
ElementProps (optional) |
Attributes, event listeners, className, and styles. |
children |
Children[] |
The child elements (text, numbers, elements, or nested arrays). |
classNameβ Setsclassattribute.styleβ Supports inline styles as an object or string.
- Supports event handlers like React (
onClick,onChange,onMouseEnter, etc.). - Automatically converts
onEventNameto the correct event type.
- Any valid HTML attribute (e.g.,
id,title,href, etc.).
dotElement is fully typed! π―
const heading: HTMLHeadingElement = createElement("h1", {}, "Welcome!");MIT License Β© 2025. Feel free to use, modify, and contribute! π
- NPM: dotElement on npm
- GitHub: dotElement Repository
π‘ Contributions & Issues: Feel free to open an issue or submit a PR on GitHub!