Listing known CSS classes using Javascript

Posted by Fred Oliveira on Stack Overflow See other posts from Stack Overflow or by Fred Oliveira
Published on 2011-01-10T21:42:37Z Indexed on 2011/01/10 21:53 UTC
Read the original article Hit count: 179

Filed under:
|
|
|

I'm trying to find a good way to collect the names of classes defined in the stylesheets included with a given document. I know about document.StyleSheetList but it doesn't seem like it'd be easy to parse. What I'm looking for is something like, for a stylesheet document such as:

.my_class { 
    background: #fff000; 
}
.second_class {
    color: #000000;
}

I could extract an array like ["my_class", "second_class"]. This obviously assumes the favorable scenario of a fully loaded dom and stylesheets.

I've been looking everywhere for a good way to do something like this and so far, have made little progress. Does anyone have any idea about how to pull this off? Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery