Skip to content

Instantly share code, notes, and snippets.

@Pustelto
Created October 13, 2016 08:47
Show Gist options
  • Save Pustelto/cb27b73121628308029c71ce2efb452d to your computer and use it in GitHub Desktop.
Save Pustelto/cb27b73121628308029c71ce2efb452d to your computer and use it in GitHub Desktop.
Very simple class toggler
// =============
// 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