HtmlAttributeManager
is a JavaScript class for managing HTML elements with specific attributes.
npm install html-attribute-manager
Click for npmJS.com URL
Click for Documentation URL
First, import HtmlAttributeManager
into your JavaScript file:
const HtmlAttributeManager = require('html-attribute-manager');
Then, create an instance of HtmlAttributeManager by providing an object containing attribute-function pairs:
const attributeManager = new HtmlAttributeManager({
"toggle-visibility": "toggleVisibility",
"change-color": "changeColor"
});
HtmlAttributeManager(attributeName, functionName) Creates an instance of HtmlAttributeManager.
-
attributeName (
string
): The name of the HTML attribute to search for. -
functionName (
string
): The name of the function to call for each matching element.
handleEvent()
Finds HTML elements with the specified attribute and calls the corresponding function.
destroy()
Removes the event listener when the instance is no longer needed.
// Define functions
window.toggleVisibility = function(element, value) {
if (value === 'true') {
element.style.display = 'block';
} else {
element.style.display = 'none';
}
};
window.changeColor = function(element, color) {
element.style.color = color;
};
// Create an instance of HtmlAttributeManager
const attributeManager = new HtmlAttributeManager({
"toggle-visibility": "toggleVisibility",
"change-color": "changeColor"
});
Contributions are welcome! Please feel free to submit issues or pull requests on Github.
This project is licensed under the MIT License - see the LICENSE file for details.