get css config value
by chim
HTML
<div id="result">
</div>
CSS
.this-is-config.variableName
{
/* quotes works and is valid css */
quotes:"circle";
/* content works, but should only be for pseudo elements */
content: "hey-hey";
/* Some other rules will not work */
color: "rouge";
}
JavaScript
function getConfig(variableName) {
// search backwards because the last match is more likely the right one
for (var s= document.styleSheets.length - 1; s >= 0; s--) {
var cssRules = document.styleSheets[s].cssRules ||
document.styleSheets[s].rules || []; // IE support
for (var c=0; c < cssRules.length; c++) {
if (cssRules[c].selectorText === '.this-is-config.' + variableName)
return cssRules[c].style['quotes'];
}
}
return null;
}
var value = getConfig('variableName');
document.getElementById('result').innerHTML = value;