This works in Firefox, and kinda works in Chrome:
function getCss(className) {
for (var i = 0; i < document.styleSheets.length; i++) {
for (var j = 0; j < document.styleSheets[i].cssRules.length; j++) {
if (document.styleSheets[i].cssRules[j].selectorText == "." + className) {
return document.styleSheets[i].cssRules[j].cssText;
}
}
}
return "";
}
For IE, something along these lines might get you on the right track...
var elem = document.getElementById('foo');
var styleInfo = '';
for (var style in elem.currentStyle) {
styleInfo += style + ": " + elem.currentStyle[style] + "\n";
}
Depending on the exact problem you're trying to solve, another possible (hacky) approach is to get the style elements (document.getElementsByTagName("style")
), and then use a regular expression to search their innerHTML
for the text you want