How to remove CSS rules by JavaScript?
var elStyle = document.querySelector('style#the-style');
var stylesheet = elStyle.sheet;
var rules = stylesheet.cssRules;
for (var i=0; i<rules.length; i++) {
var rule = rules[i];
if (rule.selectorText === '#rule2 em') {
// TODO: remove this rule
break;
}
}
I succeeded to remove the style by rule.style.color=''
but the rule still exists. Are there any APIs to remove? Or should I use innerHTML
?
UPDATE
In this case, I'd like to remove style rules, not style properties.
(I don't know about Stack Overflow's rule well. I hope this editing was right.)