开发者

all css classes in page using js

开发者 https://www.devze.com 2023-02-16 19:56 出处:网络
i want to be able to get all开发者_如何学Python 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

i want to be able to get all开发者_如何学Python 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?


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')
0

精彩评论

暂无评论...
验证码 换一张
取 消