Javascript Reference
Categories: document

javascript document createStyleSheet( )

@March 15, 2008, 1:22 a.m.
createStyleSheet( ) Firefox/Netscape/NN n/a IE 4 Chrome/Safari/DOM n/a

createStyleSheet(["url"[, index]])

This method performs the same actions in IE for Windows and Macintosh, but their returned values differ. Moreover, the specific actions in the document tree depend upon the parameters passed with the method. When no parameters are included, the method inserts a blank style element into the document tree. This style element, however, is not reflected in the document.styleSheets collection until you add one or more style rules to the object. But if you specify a URL to an external .css file as the first parameter, the method creates and inserts a link element into the document's head section, bringing the external style rules to life immediately.

 

IE for Windows always returns a reference to a styleSheet object; IE for Macintosh returns a reference to the newly inserted element, which will be a style or link element, depending on the parameter makeup. The inserted style element reference is of little help for adding a rule because you can't reference the styleSheet object. For cross-operating-system compatibility, it's best to use this method only for external style sheets.

 
Parameters
 
url

A string of the URL of an external .css style sheet definition file.

index

Optional zero-based integer that indicates where among the styleSheets[] collection this new style sheet should be inserted. Default behavior is to append to the end of the collection, but this may affect cascading rules for your document.

 
Returned Value

styleSheet object reference (Windows); style or link element object reference (IE 5 and later for Macintosh).


Powered by Linode.