Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 15. Cascading Style Sheets > Iterating Over All Stylesheets

15.4. Iterating Over All Stylesheets

While getting a list of the top-level style sheets is easy using the styleSheets collection, this is potentially not a complete list of the style sheets in a document, when you take into consideration imports. To get all the style sheets you will have to iterate over the imports collection of each style sheet (in IE) and each cssRule with a type of 3 (in other browsers). To do this, the first thing you might do is export all the top-level style sheets into a regular array. You do this to avoid changing the built-in styleSheets object accidentally:

// This will hold all our style sheets
var styleCollection = [];
// This will keep track of which ones we've looked at
var indexedStylesheets = 0;

// Copy all the style sheets at the top level to the array
for (var i = 0; i < document.styleSheets.length; i++)
    styleCollection[styleCollection.length] = document.styleSheets[i];


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial