Create callback functions for any EventTarget dispatched on HTML elements.
import { Elevent } from "https://cdn.jsdelivr.net/npm/elevent/src/Elevent.mjs"
new Elevent("click", document.querySelector("#myButton"), () => console.log("Button clicked!")); // console: "Button clicked"
new Elevent("click", document.querySelectorAll("button"), (event) => console.log(event)); // console: PointerEvent
// Bind all elements that match the CSS selector string
new Elevent("click", ".css-selector", (event, elevent) => console.log(event, elevent)) // console: PointerEvent, Elevent
New elements added to the DOM with a matching CSS selector will bind automatically
const elevent = new Elevent("click", null, () => {}); // Empty Elevent instance
elevent.remove(document.querySelector("#specialButton")); // Remove a specific HTMLElement if bound
elevent.remove(); // Remove ALL currently bound elements
const elevent = new Elevent("click", null, () => {}); // Empty Elevent instance
elevent.bind(document.querySelector("#bindMe"));
Elevent.constructor(
eventType: string | null
target: NodeList | HTMLElement | string | null,
callback: CallableFunction
)
this.bind(
target: HTMLElement
)
this.remove(
target?: HTMLElement
)