I know it is not common way to modify CSS classes... but anyway >> I have the following function to change CSS parameter with JavaScript:
function changeCSSParameter(classId, param, value)
{
var CSSRules;
if (document.all)
{
CSSRules = 'rules';
}
else if (document.getElementById)
{
CSSRules = 'cssRules';
}
for (var i = 0; i < document.styleSheets[0][CSSRules].length; i++)
{
var classes = document.styleSheets[0][CSSRules][i].selectorText.split(/\s*,\s*/);
for (var j = 0; j < classes.length; j++)
{
if (classes[j] == classId)
{
document.styleSheets[0][CSSRules][i].style.setProperty(param, value, '');
}
}
}
}
However this function would not work as I wish if style classes are defined in groups, such as
.first, .second
{
color: red;
}
...because any change would apply to both classes. How can I solve this issue? Please advice.
No jQuery, please, just old-fashion JavaScript.