Created
October 13, 2016 08:47
-
-
Save Pustelto/cb27b73121628308029c71ce2efb452d to your computer and use it in GitHub Desktop.
Very simple class toggler
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
// ============= | |
// CLASS TOGGLER | |
// ============= | |
(function(){ | |
const togglers = document.querySelectorAll('.js-toggler'); | |
togglers.forEach(elm => { | |
elm.addEventListener('click', toggleClass); | |
}); | |
function toggleClass(e){ | |
const toggler = this; | |
const tgt = toggler.getAttribute('data-toggler-target'); | |
const cls = toggler.getAttribute('data-toggler-class'); | |
document.querySelector(tgt).classList.toggle(cls); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment