https://github.com/snugug/data-state
Small JavaScript helper for working with the `data-state` attribute of an element
https://github.com/snugug/data-state
Last synced: about 1 year ago
JSON representation
Small JavaScript helper for working with the `data-state` attribute of an element
- Host: GitHub
- URL: https://github.com/snugug/data-state
- Owner: Snugug
- License: mit
- Created: 2014-08-14T19:57:12.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-08-23T02:30:35.000Z (almost 12 years ago)
- Last Synced: 2025-04-14T16:07:46.503Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 211 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Data-State
==========
Small JavaScript helper for setting the `data-state` attribute of an element
## Installation
Data State can be installed via Bower
```bash
$ bower install data-state --save
```
It will either present itself as the global `state` variable or be available via `define`/`module.exports`, depending on what's available.
## Usage
* `state.get(el)` - Returns an array of states for the given element `el`, or `null` if it has no states
* `state.has(el, has)` - Returns `true` if the element `el` has the given state `has`
* `state.add(el, add)` - Adds the state `add` to the element `el`. If a state gets added that already exists, will not be added twice
* `state.set(el, add)` Same as `state.add`
* `state.remove(el, remove)` - Removes the state `state` from the element `el`. If multiple states present, will only remove the given state. If the last state gets removed, the `data-state` attribute will be removed
* `state.toggle(el, toggle)` - Removes the state `toggle` from the element `el` using `state.remove`, if it exists, otherwise adds it using `state.add`