i want to be able to get all the class names of all css files on the page. Is there any existing possibility or do i have to read it and parse it by myself. Isn´t there any api of the browser?
            Asked
            
        
        
            Active
            
        
            Viewed 4,038 times
        
    4
            
            
        - 
                    Please clarify: Are you asking how to find out the names of all **HTML classes** that are mentioned in **class selectors** that form all or part of the **selectors** for all **rule sets** in all the CSS that is loaded from **external files**? (I suspect this is only partially right). – Quentin Mar 15 '11 at 16:50
 - 
                    Do you mean all `class="..."` names? – pimvdb Mar 15 '11 at 16:52
 - 
                    Or all the values in the `class` attributes on `` elements that are `rel=stylesheet`? – Quentin Mar 15 '11 at 16:53
 - 
                    If you want all classes applied to elements in the page, see [this question](http://stackoverflow.com/questions/1795735/find-all-css-styles-used-on-website). – justkt Mar 15 '11 at 16:59
 - 
                    sorry for late reply, no, i need all available classes in all files and all onpage style rules, not just that are placed in html elements like class="..." – Luke Mar 16 '11 at 14:01
 
1 Answers
2
            is maybe a dulplicate request of this? How do you read CSS rule values with JavaScript?
function getStyle(className) {
    var classes = document.styleSheets[0].rules || document.styleSheets[0].cssRules
    for(var x=0;x<classes.length;x++) {
        if(classes[x].selectorText==className) {
                (classes[x].cssText) ? alert(classes[x].cssText) : alert(classes[x].style.cssText);
        }
    }
}
getStyle('.test')
        Community
        
- 1
 - 1
 
        Achilleterzo
        
- 742
 - 6
 - 16
 
- 
                    Hej thank you, it´s not the exact answer, but it told me what i needed to now. I needed the document.styleSheets -> rules -> selectorText. If you want, you can change your code so I get all selectorText items in one list. +1 – Luke Mar 16 '11 at 14:04