AwaitedDOM/ CSSStyleSheet

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 rules are contained in a CSSRuleList, which can be obtained from the stylesheet's cssRules property.
For example, one rule might be a CSSStyleRule object containing a style such as:

Properties

.cssRules
W3C

Returns a live CSSRuleList which maintains an up-to-date list of the CSSRule objects that comprise the stylesheet.

This is normally used to access individual rules like this:

styleSheet.cssRules[i] // where i = 0..cssRules.length-1

To add or remove items in cssRules, use theĀ CSSStyleSheet's insertRule() and deleteRule() methods.

Type: CSSRuleList

.ownerRule
W3C

If this stylesheet is imported into the document using an @import rule, the ownerRule property returns the corresponding CSSImportRule; otherwise, this property's value is null.

Type: CSSRule

Methods

.deleteRule(index)
W3C

Deletes the rule at the specified index into the stylesheet's rule list.

Arguments:

  • index number. The index into the stylesheet's CSSRuleList indicating the rule to be removed.

Returns: Promise<void>

.insertRule(rule, index?)
W3C

Inserts a new rule at the specified position in the stylesheet, given the textual representation of the rule.

Arguments:

  • rule string.

    A string containing the rule to be inserted. What the inserted rule must contain depends on its type:

    • **For rule-sets**, both a selector and a style declaration.
    • **For at-rules**, both an at-identifier and the rule content.
  • index number. A positive integer less than or equal to stylesheet.cssRules.length, representing the newly inserted rule's position in CSSStyleSheet.cssRules. The default is 0. (In older implementations, this was required. See Browser compatibility for details.)

Returns: Promise<number>

Unimplemented Specs

Properties

disabledhref
mediaownerNode
parentStyleSheettitle
type

Edit this page on GitHub