addRule Method

MS Office DHTML, HTML & CSS

 
Click to return to the DHTML, HTML & CSS home page    
addReadRequest Method     alert Method     DHTML Methods    

addRule Method


Creates a new style rule for the styleSheet object, and returns the index into the rules collection.

Syntax

styleSheet.addRule(sSelector, sStyle [, iIndex])

Parameters

sSelectorRequired. String that specifies the selector for the new rule. Single contextual selectors are valid. For example, "DIV P B" is a valid contextual selector.
sStyleRequired. 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.
iIndexOptional. Integer that specifies the location in the rules collection to add the new style rule. If an index is not provided, the rule is added to the end of the collection by default.

Return Value

The return value is reserved; do not use.

Remarks

You can apply rules to a disabled styleSheet, but they do not apply to the document until you enable the styleSheet.

Example

This example uses the addRule method to add a rule that sets all bold text appearing in a DIV to the color blue.

<DIV>
Internet Explorer makes <B>HTML</B> dynamic.
</DIV>

<SCRIPT>
   var new_rule;
   new_rule = styleSheets[0].addRule("DIV B", "color:blue", 0);
</SCRIPT>

This example uses the addRule method to add two rules to the end of the rules collection. The rules apply the hover and link pseudo-class attributes to all anchors that appear within an H2 heading.

<H2>
<A HREF="http://www.microsoft.com/">
    Where Do You Want to Go Today?
</A>
</H2>

<SCRIPT>
   document.styleSheets[0].addRule("H2 A:hover", "color:gold");
   document.styleSheets[0].addRule("H2 A:link", "color:black");
</SCRIPT>

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.

styleSheet

See Also

removeRule, rules, styleSheets

Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.