StyleSheet object (Object/DOM)

An object that represents a style sheet.

Availability:

DOM level - 2
JavaScript - 1.5
JScript - 3.0
Internet Explorer - 4.0
Netscape - 6.0
JavaScript syntax:-myStyleSheet = myDocument.styleSheets[anIndex]
IEmyStyleSheet = myDocument.createStyleSheet()
Argument list:anIndexA valid reference to an item in the collection
Object properties:cssText, disabled, href, id, media, ownerNode, owningElement, owningNode, parentStyleSheet, readOnly, title, type
Object methods:addImport(), addRule(), removeRule()
Collections:cssRules[], imports[], rules[]

A style sheet contains many individual style objects which are managed as a collection. These style sheet objects are created by means of the <STYLE> HTML tag or are imported with the <LINK> tag. They can also be created by means of the @import statement inside a style definition.

The Document.styleSheets[] collection contains a reference for every styleSheet object in the document.

Beware that a STYLE object and a style object are different things. A STYLE object is instantiated by the <STYLE> HTML tag and contains properties that reflect its attributes.

This is quite different to a style object which is a member of a styleSheet and describes the rules for a particular style.

DOM level 2 adds the following properties:

It also adds the following methods:

Warnings:

See also:Document.createStyleSheet(), Document.styleSheets[], Element.style, rule object, Style sheet, StyleSheetList object

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
cssText n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
disabled1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a2 2 n/a n/a-
href1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a2 2 n/a n/aReadOnly.
id n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/aReadOnly.
media1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a2 2 n/a n/aWarning , ReadOnly.
ownerNode1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a2 2 n/a n/aReadOnly.
owningElement n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly.
owningNode n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
parentStyleSheet1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a2 2 n/a n/aReadOnly.
readOnly1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly.
title1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a2 2 n/a n/aWarning , ReadOnly.
type1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a2 2 n/a n/aReadOnly.

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
addImport() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
addRule() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
removeRule() n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-