Skip to content

Instantly share code, notes, and snippets.

@rebelchris
Created July 13, 2020 14:01
Show Gist options
  • Save rebelchris/365f26f95d7e9f432f64f21886d9b9ef to your computer and use it in GitHub Desktop.
Save rebelchris/365f26f95d7e9f432f64f21886d9b9ef to your computer and use it in GitHub Desktop.
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;
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