Last active
June 6, 2020 15:09
-
-
Save tail-call/22a31626f8e8fb8de1dab2092f73103a to your computer and use it in GitHub Desktop.
Evil CSSStyleSheet manipulations: removing all css rules that apply to a specific element
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
function removeRulesThatApplyTo(element) { | |
for (let sheet of [...document.styleSheets]) { | |
for (let rule of [...sheet.cssRules]) { | |
if (element.matches(rule.selectorText)) { | |
sheet.removeRule([...sheet.cssRules].indexOf(rule)); | |
} | |
} | |
} | |
} |
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
document.addEventListener('click', event => { | |
event.preventDefault(); | |
event.stopPropagation(); | |
removeRulesThatApplyTo(event.target); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe it's useful for stylesheets debugging I dunno...