This page is Almost Ready

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

insertRule

Summary

Adds a new CSS rule to the stylesheet.

Method of css/cssom/styleSheetcss/cssom/styleSheet

Syntax

var index = stylesheet.insertRule(ruleText, index);

Parameters

ruleText

Data-type
String

The at-identifier ("@rule_name") and the rule content.

index

Data-type
Number

The index within the style sheet’s rule list of the rule before which to insert the specified rule. If the specified index equals the length of the style sheet’s rule list, the rule will be added to the end of the style sheet.

Return Value

Returns an object of type NumberNumber

The newly inserted rule’s index within the style sheet’s rule list.

Notes

After the new rule has been inserted, it becomes part of the cascade.

Related specifications

DOM Level 2 Style
Recommendation

See also

Related pages

Attributions