Last active
December 12, 2015 09:39
-
-
Save MoOx/4753179 to your computer and use it in GitHub Desktop.
Please show me how will you write that without jQuery please :)
(It's not I'm not able to do it, but you already know that right ?)
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
// togglable ability (used for navbar) | |
$('.js-togglable').each(function() { | |
var togglableContainer = this; | |
$('.js-togglable__toggler', togglableContainer).on('click keyup', function() { | |
$('.js-togglable__item', togglableContainer).toggleClass('js-togglable__item--hide'); | |
}); | |
}); |
I found an other way for the forEach
trick.
Array.prototype.slice.call(document.querySelectorAll('.js-togglable')).forEach(function(el){
var toggler = el.querySelector('.js-togglable__toggler');
var items = Array.prototype.slice.call(el.querySelectorAll('.js-togglable__item'));
var toggle = function(event) {
items.forEach(function(item) {
item.classList.toggle('js-togglable__item--hide');
});
};
toggler.addEventListener('click', toggle);
toggler.addEventListener('keyup', toggle);
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So I just need to add
NodeList.prototype.forEach = Array.prototype.forEach;
to make this work like a charm. Bye jQuery :)Thanks @anthonyshort !
Now I just need a nice way to includes polyfills to support old browsers :)