all css classes in page using js
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')
精彩评论