XML DOM insertRule() methode

Definitie en gebruik

De insertRule() methode voegt een regel toe aan de stylesheet.

Syntaxis:

insertRule(rule,index)
Parameters Description
rule

Verplicht. Een volledige, oplosbare tekstrepresentatie van de regel die moet worden toegevoegd aan de stylesheet.

  • For rule sets (rule sets),rule Indicates the selector and style declarations.
  • For @ rules (At rules),rule Indicates the @ identifier and the rule content.
index Required. The position to insert or append the rule to the cssRules array.

Return value

The value of the parameter index.

Throw

This method will throw an exception with the following code under the following conditions: DOMException exception:

HIERARCHY_REQUEST_ERR
CSS syntax does not allow the specified rule to appear at the specified position.
INDEX_SIZE_ERR
index Does not correspond to any rule in the rule set of the stylesheet, such as index Is a negative number or a value greater than cssRules.length.
NO_MODIFICATION_ALLOWED_ERR
This stylesheet is read-only.
SYNTAX
specified rule The text has a text error.

Description

This method will place in the cssRules array of the stylesheet at the specified index Insert (or append) a new CSS rule. This is a DOM standard method, please refer to CSSStyleSheet.addRule(), it is an alternative method specific to IE.

Example

Push a rule to the top of the stylesheet:

myStyle.insertRule("#blanc { color: white }", 0);

Related pages

XML DOM reference manual:CSSStyleSheet.addRule()