createStyleSheet Method
createStyleSheet Method

Creates a style sheet for the document.

Syntax

oStylesheet = object.createStyleSheet( [sURL] [, iIndex])

Parameters

sURL Optional. A String that specifies how to add the style sheet to the document. If a file name is specified for the URL, the style information is added as a link object. If the URL contains style information, it is added to the style object.
iIndex Optional. A Integer that specifies the index that indicates where the new style sheet is inserted in the styleSheets collection. The default is to insert the new style sheet at the end of the collection.

Return Value

Returns a styleSheet object.

Remarks

You can create up to 31 styleSheet objects with the createStyleSheet method. After that, the method returns an "Invalid Argument" exception. To create additional objects, use createElement and append them to the HEAD of the document as follows:

var styleSheet = document.createElement('STYLE');
document.documentElement.firstChild.appendChild(styleSheet);

Example

This example uses the createStyleSheet method to create a link to a style sheet.

document.createStyleSheet('styles.css');

Standards Information

There is no public standard that applies to this method.

Applies To

document, HTMLDocument Constructor
Community Content

Upper limit is 31
Added by:John Sudds

You can only create 31 stylesheet objects with this method. After that, it throws an "Invalid argument" exception.

The same limit applies even if you create a STYLE element and append it to the document, as follows:

var ss = document.createElement('STYLE');
document.documentElement.firstChild.appendChild(ss);
© 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