@hoge1e3/dom-bind
v1.0.0
Published
Bind object to dom element
Maintainers
Readme
@hoge1e3/dom-bind
A lightweight utility to bind plain JavaScript objects to DOM elements.
Features
- Bind objects to DOM elements with ease
- Retrieve and remove bindings when needed
- Zero dependencies, simple API
Installation
npm install @hoge1e3/dom-bindUsage
import { bind, bounded, unbind } from '@hoge1e3/dom-bind';
const obj = { name: 'Alice' };
const element = document.querySelector('#myElement');
bind(element, obj); // Binds obj to the DOM element
const boundObj = bounded(element); // Retrieves the bound object
unbind(element); // Removes the bindingAPI
bind(element: Node | string, object: object): object
Binds an object to a DOM element. Accepts either a DOM node or a CSS selector.
bounded(element: Node | string): object
Retrieves the object bound to the DOM element.
unbind(element: Node | string): void
Removes the object binding from the DOM element.
License
MIT
