CSSGroupingRule.insertRule()
The insertRule() method of the
CSSGroupingRule interface adds a new CSS rule to a list of CSS rules.
Syntax
cssGroupingRule.insertRule(rule);
cssGroupingRule.insertRule(rule, index);
Parameters
- rule
- indexOptional
-
An optional index at which to insert the rule; defaults to 0.
Return value
The index of the new rule.
Exceptions
IndexSizeErrorDOMException-
Thrown if index is greater than the number of child CSS rules.
HierarchyRequestErrorDOMException-
Thrown if, due to constraints specified by CSS, the new rule cannot be inserted into the list at the (zero-index) index position given.
InvalidStateErrorDOMException-
Thrown if the new rule is an
@namespaceat-rule, and the list of child CSS rules contains anything other than@importat-rules and@namespaceat-rules.
Examples
let myRules = document.styleSheets[0].cssRules;
myRules[0].insertRule('html {background-color: blue;}',0); /* inserts a rule for the html element at position 0 */
Specifications
| Specification |
|---|
| CSS Object Model (CSSOM) # dom-cssgroupingrule-insertrule |
Browser compatibility
BCD tables only load in the browser