Export (0) Print
Expand All

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.

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

PropertyAccess typeDescription

constructor

Returns a reference to the constructor of an object.

cssRules

Retrieves a list of all CSS rules contained within the parent object.

cssText

Read/write

Sets or retrieves the persisted representation of the style rule.

disabled

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.

id

Sets or retrieves the string identifying the object.

isAlternate

Retrieves a value that indicates whether the IHTMLStyleSheet3 object is an alternative style sheet.

isPrefAlternate

Retrieves a value that indicates whether the IHTMLStyleSheet3 object is the preferred style sheet.

media

Sets or retrieves the media type.

ownerNode

Retrieves the node that associates this style sheet with the document.

ownerRule

Retrieves a value that indicates whether this style sheet comes from an @import rule or a link (an element or processing instruction).

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 document or is imported.

textAutospace

Specifies the autospacing and narrow space width adjustment of text.

title

Sets or retrieves the title of the style sheet.

type

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.

Note  For the style element, styleSheet is no longer supported in Edge document mode for Internet Explorer 11. Starting with IE11, use sheet.

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>

 

 

Show:
© 2014 Microsoft