styleSheet object
Represents a single style sheet in the document.
Members
The styleSheet object has these types of members:
Methods
The styleSheet object has these methods.
| Method | Description |
|---|---|
| addImport |
Adds a style sheet to the imports collection for the specified style sheet. |
| addPageRule |
Not implemented. Creates a new page object for a style sheet. |
| addRule |
Creates a new rule for a style sheet. |
| deleteRule |
Deletes a rule from the style sheet. |
| fireEvent |
Fires a specified event on the object. |
| insertRule |
Inserts a new rule into the style sheet. |
| 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. |
Properties
The styleSheet object has these properties.
| Property | Access type | Description |
|---|---|---|
|
Returns a reference to the constructor of an object. | ||
|
Retrieves a list of all CSS rules contained within the parent object. | ||
|
Read/write |
Sets or retrieves the persisted representation of the style rule. | |
|
Sets or retrieves a value that indicates whether the user can interact with the object. | ||
|
Sets or retrieves the URL of the linked style sheet. | ||
|
Sets or retrieves the string identifying the object. | ||
|
Retrieves a value that indicates whether the IHTMLStyleSheet3 object is an alternative style sheet. | ||
|
Retrieves a value that indicates whether the IHTMLStyleSheet3 object is the preferred style sheet. | ||
|
Sets or retrieves the media type. | ||
|
Retrieves the node that associates this style sheet with the document. | ||
|
Retrieves a value that indicates whether this style sheet comes from an @import rule or a link (an element or processing instruction). | ||
|
Retrieves the next object in the HTML hierarchy. | ||
|
Retrieves the style sheet that imported the current style sheets. | ||
|
Retrieves whether the rule or style sheet is defined on the document or is imported. | ||
|
Specifies the autospacing and narrow space width adjustment of text. | ||
|
Sets or retrieves the title of the style sheet. | ||
|
Retrieves the CSS language in which the style sheet is written. |
Standards information
There are no standards that apply here.
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.
Examples
This example uses the styleSheet object to change the cascading style sheets (CSS) values of inline and imported styles.
<!DOCTYPE html> <html> <head> <title>CSS</title> <style> body { background-color: #CFCFCF; } @import url("otherStyleSheet.css"); </style> </head> <body> <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 = "#00F"; // Add a rule for P elements to have yellow backgrounds: oStyleSheet.addRule("p", "background-color: #FF0;"); // Change an imported rule: oStyleSheet.imports[0].color = "#000"; } </script> </body> </html>