Skip to content

Instantly share code, notes, and snippets.

@MaxArt2501
Last active February 16, 2018 13:27
Show Gist options
  • Save MaxArt2501/c070925a7437a8f8a42a7e724a2260ff to your computer and use it in GitHub Desktop.
Save MaxArt2501/c070925a7437a8f8a42a7e724a2260ff to your computer and use it in GitHub Desktop.
Add second argument support in DOMTokeList.toggle (e.g. for Internet Explorer)
(function(dtl) {
if (!dtl) return;
var elem = document.createElement("div");
div.classList.toggle("test", false);
if (div.className === "test")
dtl.prototype.toggle = (function(toggle) {
return function(cls, force) {
if (typeof force === "boolean")
return this[force ? "add" : "remove"](cls);
return toggle.call(this, cls);
};
})(dtl.prototype.toggle);
})(window.DOMTokenList);
@frudolf
Copy link

frudolf commented Feb 16, 2018

var elem = [...] should be var div = [...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment