Skip to content

Instantly share code, notes, and snippets.

@w8r
Last active December 30, 2015 10:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w8r/fbdbfea078629ff913d4 to your computer and use it in GitHub Desktop.
Save w8r/fbdbfea078629ff913d4 to your computer and use it in GitHub Desktop.
IE10+ DOMTokenList fix
/**
* IE 10 + supports ClassList, but the standards are vague. It is extremely
* convenient to add several classnames at once, FF and Chrome support that.
*
* @author Alexander Milevski <info@w8r.name>
*
* https://gist.github.com/w8r/fbdbfea078629ff913d4
*
* MIT License
*
* @param {DOMTokenList} DOMTokenList
*/
(function(DOMTokenList) {
if (typeof DOMTokenList === 'undefined') {
return;
}
var el = document.createElement('_');
el.classList.add('a', 'b');
// duck-typing
if (el.classList.length !== 2) {
DOMTokenList.prototype.__add__ = DOMTokenList.prototype.add;
DOMTokenList.prototype.add = function() {
for (var i = 0, len = arguments.length; i < len; i++) {
this.__add__(arguments[i]);
}
};
DOMTokenList.prototype.__remove__ = DOMTokenList.prototype.remove;
DOMTokenList.prototype.remove = function() {
for (var i = 0, len = arguments.length; i < len; i++) {
this.__remove__(arguments[i]);
}
};
}
})(DOMTokenList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment