Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mjlescano/toggle-parent
Toggle class on parent element.
https://github.com/mjlescano/toggle-parent
Last synced: 22 days ago
JSON representation
Toggle class on parent element.
- Host: GitHub
- URL: https://github.com/mjlescano/toggle-parent
- Owner: mjlescano
- License: mit
- Created: 2015-04-15T17:10:52.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-25T14:42:19.000Z (almost 8 years ago)
- Last Synced: 2024-08-31T16:49:23.084Z (2 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Toggle Parent
Simple component to toggle a class on parentNode of an element. When activated
a backdrop element (`.toggle-parent-backdrop`) is added that will remove the
class when clicked.## Installation
With [npm](https://github.com/component/component):
```
$ npm install toggle-parent
```With [component](https://github.com/component/component):
```
$ component install mjlescano/toggle-parent
```## Example
```html
#dropdown-container.active .dropdown-menu {
display: block;
}.dropdown-menu {
display: none;
}
Toggle Menu
- option 1
- option 2
- option 3
``````js
var ToggleParent = require('toggle-parent');var button = document.querySelector('#dropdown-container button');
// Every time 'button' is pressed, the class 'active' will
// be toggled on '#dropdown-container'
var dropdown = new ToggleParent(button);// Toggle programatically
dropdown.toggle()
```## Options
Options that can be passed as a second argument to `new ToggleParent(button, opts)`* **parent**: Element to toggle the class (Default: button.parentNode)
* **toggleClass**: Class name to be toggled (Default: `active`)## API
* **.show()**: Add `toggleClass` to `parent`
* **.hide()**: Remove `toggleClass` from `parent`
* **.toggle()**: Toggle `toggleClass` on `parent`
* **.destroy()**: Remove ToggleParent instance, with all the events attached.## License
MIT