Export (0) Print
Expand All
8 out of 12 rated this helpful - Rate this topic

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.

-1

Default. The rule is added to the end of the collection.

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

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.