js-event-listener-utils
v1.0.2
Published
a lightweight utility library for managing custom event listeners in vanilla JavaScript projects. It provides a flexible interface to selectively listen for events on specified elements based on attributes, enabling efficient event handling and data loggi
Downloads
6
Readme
js-event-listener-utils
js-event-listener-utils is a lightweight utility library for managing custom event listeners in vanilla JavaScript projects. It provides a flexible interface to selectively listen for events on specified elements based on attributes, enabling efficient event handling and data logging. Ideal for enhancing interactivity and analytics tracking in web applications without dependencies on specific frameworks.
Features
Add Event Listeners: Attach event listeners to targeted elements based on tag types and attribute criteria.
Customizable Callbacks: Define callback functions to handle event
data, facilitating custom actions based on user interactions.Attribute-Based Filtering: Selectively trigger callbacks only when
specified attributes are present on targeted elements.
Optional Data Handling
: Manage temporary data attributes associated
with events, ensuring clean and efficient event processing.
Installation
Install js-event-listener-utils via npm:
npm install js-event-listener-utils
Usage:
const addEvent = require("js-event-listener-utils");
// Example usage
const parentSelector = '.parent-container';
const elementTypes = ['button', 'a'];
const primaryAttribute = 'data-log-click';
const callback = (primaryValue, actionString, extraParams) => {
console.log('Event data:', primaryValue, actionString, extraParams);
};
addEvent({
parentSelector,
elementTypes,
primaryAttribute,
callback
});
Contributing
Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change.
By Order of the Peaky Blinders.