styleSheet Object

DHTML, HTML, & CSS

 
Click to return to the DHTML, HTML & CSS home page    
style Object     SUB Element | SUB Object     DHTML Objects    

styleSheet Object


Represents a single style sheet in the document.

Remarks

You can use this object to retrieve style sheet information, such as the URL of the source file for the style sheet and the element in the document that owns (defines) the style sheet. You also can use it to modify style sheets.

You can retrieve a styleSheet object from the styleSheets collection or from the imports collection. Each item in these collections is a style sheet. A styleSheet object is available for a style sheet only if it is included in a document with a STYLE or LINK element, or with an @import statement in a STYLE element.

This object is available in script as of Microsoft® Internet Explorer 4.0.

Members

Example

This example uses the styleSheet object to change the cascading style sheets (CSS) values of inline and imported styles.

<STYLE>
BODY {background-color: #CFCFCF;}
@import url("otherStyleSheet.css");
</STYLE>
<SCRIPT>
window.onload=fnInit;
function fnInit(){
   // Access a rule in the styleSheet, change backgroundColor to blue.
   var oStyleSheet=document.styleSheets[0];
   var oRule=oStyleSheet.rules[0];
   oRule.backgroundColor="#0000FF";
   // Add a rule for P elements to have yellow backgrounds.
   oStyleSheet.addRule("P","background-color: #FFFF00;");
   // Change and imported rule:
   oStyleSheet.imports[0].color="#000000";
}
</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.

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.