DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Reading Attribute Values From A Stylesheet
Used for reading a value from the loaded stylesheet. Only support the usage of one stylesheet file. Supports selectors beeing grouped and defined in multiple blocks.
function getCssValue(selector,attribute)
{
selector = selector.toLowerCase();
var stylesheet = document.styleSheets[0];
var n = stylesheet.cssRules.length;
for(var i=0; i<n; i++)
{
var selectors = stylesheet.cssRules[i].selectorText.toLowerCase().split(",");
var m = selectors.length;
for(j=0; j<m; j++)
{
if(selectors[j].trim() == selector)
{
var value = stylesheet.cssRules[i].style.getPropertyValue(attribute);
if(value!="")
{
return value;
}
}
}
}
debug("Could not find selector/attribute: "+selector+"/"+attribute);
return null;
},





