0
ブラウザ:クローム60.0.3112.78なぜchromeが間違ったCSSクラスを削除するのですか?
オリジナル:
CSSRuleList {0: CSSStyleRule, 1: CSSStyleRule, 2: CSSStyleRule, 3: CSSStyleRule, length: 4}
length:4
0:CSSStyleRule {selectorText: ".highlight", style: CSSStyleDeclaration, type: 1, cssText: ".highlight { background-color: rgb(182, 246, 156); }", parentRule: null, …}
1:CSSStyleRule {selectorText: ".highlight:hover", style: CSSStyleDeclaration, type: 1, cssText: ".highlight:hover { background-color: rgb(124, 208, 124); }", parentRule: null, …}
2:CSSStyleRule {selectorText: ".highlightb6f69c:hover", style: CSSStyleDeclaration, type: 1, cssText: ".highlightb6f69c:hover { background-color: rgb(124, 208, 124); }", parentRule: null, …}
3:CSSStyleRule {selectorText: ".highlightb6f69c", style: CSSStyleDeclaration, type: 1, cssText: ".highlightb6f69c { background-color: rgb(182, 246, 156); }", parentRule: null, …}
操作:
> document.getElementById('styles').sheet.removeRule('.highlightb6f69c')
<- undefined
> document.getElementById('styles').sheet.rules
<- CSSRuleList {0: CSSStyleRule, 1: CSSStyleRule, 2: CSSStyleRule, 3: CSSStyleRule, length: 3}
length:3
0:CSSStyleRule {selectorText: ".highlight:hover", style: CSSStyleDeclaration, type: 1, cssText: ".highlight:hover { background-color: rgb(124, 208, 124); }", parentRule: null, …}
1:CSSStyleRule {selectorText: ".highlightb6f69c:hover", style: CSSStyleDeclaration, type: 1, cssText: ".highlightb6f69c:hover { background-color: rgb(124, 208, 124); }", parentRule: null, …}
2:CSSStyleRule {selectorText: ".highlightb6f69c", style: CSSStyleDeclaration, type: 1, cssText: ".highlightb6f69c { background-color: rgb(182, 246, 156); }", parentRule: null, …}
私はクラス.highlightb6f69c
を削除したいのですが、クロームではなく.highlight
を削除し、なぜですか?
removeRule(または少なくとも私がMDNで見つけることができるものからのdeleteRule)のように見えるのは、インデックスではなく名前です。 https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/deleteRule – hank