What is the difference between:
document.styleSheets[0].cssRules
and
document.styleSheets[0].rules
I noticed that the second is also supported by IE8 and previous. But what is the difference between these two objects?
The CSSRule interface specifies the properties common to all rules, while properties unique to specific rule types are specified in the more specialized interfaces for those rules' respective types. CSSRule.cssText.
CSSStyleRule represents a single CSS style rule. It implements the CSSRule interface with a type value of 1 (CSSRule. STYLE_RULE).
The CSSStyleSheet interface represents a single CSS stylesheet, and lets you inspect and modify the list of rules contained in the stylesheet. It inherits properties and methods from its parent, StyleSheet . A stylesheet consists of a collection of CSSRule objects representing each of the rules in the stylesheet.
The properties cssRules
and rules
are constructed through the same steps. Hence they result in the same object. rules
is deprecated and it is provided only for the sake of compatibility with the existing sites.
To answer your question, there is no difference at all. The object cssRules
is officially supported whereas rules
is deprecated.
See the CSSWG spec for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With