XML DOM insertRule() Method
Definition and Usage
The insertRule() method inserts a rule into the stylesheet.
Syntax:
insertRule(rule,index)
Parameter | Description |
---|---|
rule |
Mandatory. The complete, parseable text representation to be added to the stylesheet.
|
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 a DOMException 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 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()