https://github.com/oguzhan18/html-attribute-manager
Html Attribute Manager is a JavaScript class for managing HTML elements with specific attributes.
https://github.com/oguzhan18/html-attribute-manager
attributes html-attribute-manager html-attributes javascript javascript-library npm-package npmjs package
Last synced: 8 months ago
JSON representation
Html Attribute Manager is a JavaScript class for managing HTML elements with specific attributes.
- Host: GitHub
- URL: https://github.com/oguzhan18/html-attribute-manager
- Owner: oguzhan18
- Created: 2024-03-12T21:06:00.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-20T07:00:13.000Z (over 2 years ago)
- Last Synced: 2024-12-07T07:11:49.154Z (over 1 year ago)
- Topics: attributes, html-attribute-manager, html-attributes, javascript, javascript-library, npm-package, npmjs, package
- Language: JavaScript
- Homepage: https://html-attribute-manager.vercel.app/#/
- Size: 3.64 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HTML Attribute Manager
`HtmlAttributeManager` is a JavaScript class for managing HTML elements with specific attributes.
## Installation
````bash
npm install html-attribute-manager
````
Click for npmJS.com URL
Click for Documentation URL
## Usage
First, import `HtmlAttributeManager` into your JavaScript file:
`````bash
const HtmlAttributeManager = require('html-attribute-manager');
`````
Then, create an instance of HtmlAttributeManager by providing an object containing attribute-function pairs:
````bash
const attributeManager = new HtmlAttributeManager({
"toggle-visibility": "toggleVisibility",
"change-color": "changeColor"
});
````
## Constructor
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.
## Methods
`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.
## Example
````javascript
// 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"
});
````
## Contributing
Contributions are welcome! Please feel free to submit issues or pull requests on Github.
## License
This project is licensed under the MIT License - see the LICENSE file for details.