tweb-i2p/src/helpers/dom/toggleAttributePolyfill.ts
2022-04-15 15:09:21 +03:00

19 lines
462 B
TypeScript

export default function toggleAttributePolyfill() {
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;
};
}
}