4

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?

5
  • 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). Commented Mar 15, 2011 at 16:50
  • Do you mean all class="..." names? Commented Mar 15, 2011 at 16:52
  • Or all the values in the class attributes on <link> elements that are rel=stylesheet? Commented Mar 15, 2011 at 16:53
  • If you want all classes applied to elements in the page, see this question. Commented Mar 15, 2011 at 16:59
  • sorry for late reply, no, i need all available classes in all <link> files and all onpage style rules, not just that are placed in html elements like class="..." Commented Mar 16, 2011 at 14:01

1 Answer 1

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')
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.