Skip to content

Instantly share code, notes, and snippets.

@tail-call
Last active June 6, 2020 15:09
Show Gist options
  • Save tail-call/22a31626f8e8fb8de1dab2092f73103a to your computer and use it in GitHub Desktop.
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
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));
}
}
}
}
document.addEventListener('click', event => {
event.preventDefault();
event.stopPropagation();
removeRulesThatApplyTo(event.target);
});
@tail-call
Copy link
Author

Maybe it's useful for stylesheets debugging I dunno...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment