@fxi/el

1.0.0 • Public • Published

ElementCreator

Overview

ElementCreator is a JavaScript module designed to simplify the creation and management of DOM and SVG elements. It provides an intuitive API for creating elements, setting properties, attaching event listeners, and handling asynchronous content.

Features

  • Create HTML and SVG elements with ease.
  • Manage attributes, classes, and styles.
  • Attach event listeners in a structured way.
  • Support for asynchronous content.
  • Automatic cleanup of event listeners for removed elements.

Usage

First, import the module:

import { el, svg } from 'path/to/ElementCreator';

Creating an HTML Element

const div = el('div', { class: 'my-class' }, 'Hello, World!');

Creating an SVG Element

const circle = svg('circle', { cx: 20, cy: 20, r: 10 });

Attaching Event Listeners

const button = el('button', { on: ['click', () => alert('Clicked!')] });

Asynchronous Content

const asyncDiv = el('div', fetchSomeData().then(data => data.text()));

License

This project is licensed under the MIT license.

Contributions

Contributions are welcome. Please submit a pull request or open an issue for discussion.


ElementCreator - Simplifying DOM Manipulation

Package Sidebar

Install

npm i @fxi/el

Weekly Downloads

34

Version

1.0.0

License

MIT

Unpacked Size

172 kB

Total Files

18

Last publish

Collaborators

  • fxi