The StyleSheetList
interface represents a list of StyleSheet
.
It is an array-like object but can't be iterated over using Array
methods. However It can be iterated over in a standard for
loop over its indices, or converted to an Array
.
Examples
Get document styleSheet objects with for loop
for (var i=0; i < document.styleSheets.length; i++){ var styleSheet = document.styleSheets[i]; }
Get all CSS rules for the document using Array methods
var allCSS = [].slice.call(document.styleSheets) .reduce(function (prev, styleSheet) { var now = prev; try { if (styleSheet.cssRules) { now += [].slice.call(styleSheet.cssRules) .reduce(function (prev, cssRule) { return prev + cssRule.cssText; }, ''); } } catch (e) { console.log('Access to cssRules for stylesheet "' + styleSheet.href + '" is denied. Ignoring...') } return now; }, '');
Specifications
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) The definition of 'CSSStyleSheetList' in that specification. |
Working Draft |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
StyleSheetList | Chrome Full support 1 | Edge Full support Yes | Firefox Full support 31 | IE ? | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 31 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android ? |
item | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 31 | IE ? | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 31 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android ? |
length | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 31 | IE ? | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 31 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android ? |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown