Last active
May 6, 2024 12:37
-
-
Save yairEO/94280c85050274881813bbfe27c6a121 to your computer and use it in GitHub Desktop.
Remove a single property from DOM element "style" attribute
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
const removeStyleProp = (elm, prop) => | |
elm.style.cssText = elm.style.cssText // cssText automatically (luckily) adds spaces between declarations | |
.split('; ') | |
.filter(p => !p.startsWith(prop) ) | |
.join(';'); |
multi-props removal:
const removeStyleProp = (elm, props) =>
elm.style.cssText = elm.style.cssText.split('; ')
.filter(sp => props.every(p => !sp.startsWith(p)) )
.join(';');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: (demo)