Created
July 13, 2020 14:01
-
-
Save rebelchris/365f26f95d7e9f432f64f21886d9b9ef to your computer and use it in GitHub Desktop.
toggleAttribute PolyFill
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
if (!Element.prototype.toggleAttribute) { | |
Element.prototype.toggleAttribute = function(name, force) { | |
if(force !== void 0) force = !!force | |
if (this.hasAttribute(name)) { | |
if (force) return true; | |
this.removeAttribute(name); | |
return false; | |
} | |
if (force === false) return false; | |
this.setAttribute(name, ""); | |
return true; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment