Skip to content

Instantly share code, notes, and snippets.

@sevastos
Last active December 20, 2015 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevastos/6123053 to your computer and use it in GitHub Desktop.
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)
// 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