Last active
December 20, 2015 11:28
-
-
Save sevastos/6123053 to your computer and use it in GitHub Desktop.
Wrapper for adding/removing multiple classes with classList API.
Browsers do not identify multiple class names the same way (space delimited or arguments-based)
This file contains 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
// Usage: | |
// el.classList.addMany('so', 'simple'); | |
// el.classList.removeMany('inconsistencies', 'please') | |
['add', 'remove'].forEach(function(action) { | |
DOMTokenList.prototype[action + 'Many'] = function() { | |
for (var i = arguments.length - 1; i >= 0; i--) { | |
this[action](arguments[i]); | |
}; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment