Created
March 14, 2018 19:44
-
-
Save anonymous/c5c33993923d319d457eb93619778211 to your computer and use it in GitHub Desktop.
(source: https://jsfiddle.net/bLhzrne5/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .some-class { | |
| background-color: yellow; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <button data-toggle-class="#targetDiv:some-class">Toggle this Class on the Element</button> | |
| <div id="targetDiv">target</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| document.querySelectorAll('[data-toggle-class]').forEach((element) => { | |
| element.addEventListener('click', (event) => { | |
| event.preventDefault(); | |
| const [target, className] = element.getAttribute('data-toggle-class').split(':'); | |
| document.querySelector(target).classList.toggle(className); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment