styleSheet Object
styleSheet Object

Represents a single style sheet in the document.

Members Table

The following table lists the members exposed by the styleSheet object.

Attributes/Properties
Show:
AttributePropertyDescription
constructor New for Windows Internet Explorer 8  Returns a reference to the constructor of an object.
DISABLEDdisabled Sets or retrieves a value that indicates whether the user can interact with the object.
href Sets or retrieves the URL of the linked style sheet.
IDid Sets or retrieves the string identifying the object.
isAlternate New for Internet Explorer 8  Retrieves a value that indicates whether the IHTMLStyleSheet3 object is an alternative style sheet.
isPrefAlternate New for Internet Explorer 8  Retrieves a value that indicates whether the IHTMLStyleSheet3 object is the preferred style sheet.
MEDIAmedia Sets or retrieves the media type.
owningElement Retrieves the next object in the HTML hierarchy.
parentStyleSheet Retrieves the style sheet that imported the current style sheets.
readOnly Retrieves whether the rule or style sheet is defined on the page or is imported.
TITLEtitle Sets or retrieves the title of the style sheet.
type Retrieves the Cascading Style Sheets (CSS) language in which the style sheet is written.
CollectionDescription
imports Retrieves a collection of all the imported style sheets defined for the respective styleSheet object.
pages Retrieves a collection of page objects, which represent @page rules in a styleSheet.
rules Retrieves a collection of rules defined in a style sheet.
MethodDescription
addImport Adds a style sheet to the imports collection for the specified style sheet.
addPageRule Creates a new page object for a style sheet.
addRule Creates a new rule for a style sheet.
fireEvent Fires a specified event on the object.
removeImport Removes the imported style sheet from the imports collection based on ordinal position.
removeRule Deletes an existing style rule for the styleSheet object, and adjusts the index of the rules collection accordingly.
ObjectDescription
page Represents an @page rule within a styleSheet.
Style attributeStyle propertyDescription
cssText Sets or retrieves the persisted representation of the style rule.
-ms-text-autospacetextAutospace Sets or retrieves the autospacing and narrow space width adjustment of text.

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 can also 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.

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.style.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>

Standards Information

There is no public standard that applies to this object.

Applies To

styleSheets
© 2010 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View