Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the ‘cssRules’ and ‘rules’ objects?

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?

like image 485
user123123123 Avatar asked Jun 27 '16 17:06

user123123123


People also ask

What is Cssrules?

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.

What is the type value for a CSSStyleRule that represents a single style rule and implements the CSSRule interface?

CSSStyleRule represents a single CSS style rule. It implements the CSSRule interface with a type value of 1 (CSSRule. STYLE_RULE).

What is the purpose of the stylesheet API?

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.


1 Answers

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.

like image 105
manjunatha_d Avatar answered Oct 21 '22 11:10

manjunatha_d