Skip to content

Instantly share code, notes, and snippets.

Created July 13, 2020 14:01
What would you like to do?
toggleAttribute PolyFill
if (!Element.prototype.toggleAttribute) {
Element.prototype.toggleAttribute = function(name, force) {
if(force !== void 0) force = !!force
if (this.hasAttribute(name)) {
if (force) return true;
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