Instead of using
element.style.removeProperty(property)
to remove properties one at a time, I have created a utility function that can remove multiple properties at once. By extending CSSStyleDeclaration.prototype
.
Snippet:
declare global {
interface CSSStyleDeclaration {
removeProperties(...properties: Array<string>): void
}
}
CSSStyleDeclaration.prototype.removeProperties = function (...properties: Array<string>) {
for (let i = 0; i < properties.length; i++) {
/* LOGIC */
// element.style.removeProperty(properties[i])
}
}
// EXAMPLE USAGE
document.querySelector('div').style.removeProperties('top', 'right', 'bottom', ...)
The important question now is How do I select the specific element from which I want to remove properties?