IHTMLStyleSheet::addRule method
Creates a new rule for a style sheet.
Syntax
Integer* addRule( [in] String sSelector, [in] String sStyle, [in, optional] Integer iIndex = -1 );
Parameters
- sSelector [in]
-
String that specifies the selector for the new rule. Single contextual selectors are valid. For example, "div p strong" is a valid contextual selector.
- sStyle [in]
-
String that specifies the style assignments for this style rule. This style takes the same form as an inline style specification. For example, "color:blue" is a valid style parameter.
- iIndex [in, optional]
-
Integer that specifies the zero-based position in the rules collection where the new style rule should be placed.
Return value
C++
Reserved. Always returns "-1".
JavaScript
Reserved. Always returns "-1".
Remarks
You can add up to 4,095 style rules with the addRule method. After that, the method returns an "Invalid Argument" exception.
You can apply rules to a disabled styleSheet, but they do not apply to the document until you enable the styleSheet.
Examples
This example uses the addRule method to add a rule that sets all strong text appearing in a div to the color blue.
<style> </style> ... <div> Internet Explorer makes <strong>HTML</strong> dynamic. </div> <script> var new_rule; new_rule = document.styleSheets[0].addRule("div strong", "color:blue", 0); </script>
See also
- IHTMLStyleSheet
- styleSheet
- Reference
- removeRule
- rules
- styleSheets