addRuleaddRule*
*Contents  *Index  *Topic Contents
*Previous Topic: addReadRequest
*Next Topic: alert

addRule

Description

Creates a new style rule for the styleSheet object and returns the index into the Rules collection. Rules can be added to a disabled styleSheet, but they will not apply to the document unless the styleSheet has been enabled.

Syntax

integer = object.addRule(selector, style [, index])

ParameterDescription
selector String specifying the selector for the new rule. Single contextual selectors are valid. For example, "DIV P B" is a valid contextual selector.
style String specifying 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.
index Integer that specifies where in the Rules collection to add the new style rule. This is an optional parameter. If an index is not provided, the rule will be added to the end of the Rules collection by default.

Return Value

The return value is reserved; do not use.

Remarks

The following example adds a rule to the beginning of the Rules collection for all text in BOLD that appears in a <DIV> <P> tag to be set to the color blue.

var new_rule;
new_rule = styleSheets[0].addRule("DIV P B", "color:blue", 0);

Remarks

NOTE: When manipulating stylesheets through the Object Model, you will not be able to addRule() where the style is "position" to an element which doesn't already have positioning set for it. You can, however, add a rule to the object to make it "position:absolute" if the object has already been set to "position:relative" (and vice versa).

Applies To

styleSheet


Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.