removeRule Method

MS Office DHTML, HTML & CSS

 
Click to return to the DHTML, HTML & CSS home page    
removeNode Method     replace Method     DHTML Methods    

removeRule Method


Deletes an existing style rule for the styleSheet object, and adjusts the index of the rules collection accordingly.

Syntax

styleSheet.removeRule[iIndex]

Parameters

iIndexOptional. Integer that specifies the index value of the rule to be deleted from the style sheet. If an index is not provided, the first rule in the rules collection is removed.

Return Value

No return value.

Remarks

The page does not automatically reflow when the rule is removed. To see the change, you must reflow the page. You can reflow the objects affected using a number of methods. For example, you can reflow the style change only on affected text by setting the text equal to itself (see Example). Alternately, you can reload the entire page using the reload method. When you use the refresh method on a table, its content is reflowed.

Example

This example uses the removeRule method to delete a rule from the rules collection, which causes the text to reflow according to the new rules.

Sample Code

<STYLE>
P {color:green}
</STYLE>
:
<SCRIPT>
function removeTheRule() {
    // Style sheets and rules are zero-based collections; therefore,
    // the first item is item 0 in the collection.
    var iSheets = document.styleSheets.length;
    var iRules = document.styleSheets[iSheets-1].rules.length;
    // make sure there is a rule to delete
    if (1 < iRules) {            
        document.styleSheets[iSheets-1].removeRule(1);
        // Force the page to render the change.
        oEffectRules.innerHTML=oEffectRules.innerHTML;
	}
}
</SCRIPT>
:
<P ID=oEffectRules>This text has the new style applied to it.
</P>
:
<BUTTON onclick="removeTheRule()">Remove the new rule.</BUTTON>

This feature requires Microsoft® Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

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

addRule, 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.