guvenck
07-19-2007, 03:55 PM
Hello,
I wrote a small function that launches insertRule or addRule based on browser support, to change style of DOM elements.
function changeRule(selector, rule) {
var sheet = frames['testsite'].document.styleSheets[1];
if (sheet.insertRule) { // firefox
sheet.insertRule(""+selector+" { "+rule+" }", sheet.cssRules.length);
}
else if(sheet.addRule) { // ie
sheet.addRule(selector, rule);
}
}
and I call the function as follows:
var TM1 = "margin: 0; padding: 0; list-style: none; z-index: 6; font-family: "+TopmenuUlFontFamily+"; font-size: "+TopmenuUlFontSize+"px; font-weight: "+TopmenuUlFontWeight+"; text-align: "+TopmenuUlTextAlign+";";
changeRule("#topmenu ul",TM1);
It works for Firefox, but not for IE. I guess this is because addRule accepts one rule per command. How can I solve this problem?
I wrote a small function that launches insertRule or addRule based on browser support, to change style of DOM elements.
function changeRule(selector, rule) {
var sheet = frames['testsite'].document.styleSheets[1];
if (sheet.insertRule) { // firefox
sheet.insertRule(""+selector+" { "+rule+" }", sheet.cssRules.length);
}
else if(sheet.addRule) { // ie
sheet.addRule(selector, rule);
}
}
and I call the function as follows:
var TM1 = "margin: 0; padding: 0; list-style: none; z-index: 6; font-family: "+TopmenuUlFontFamily+"; font-size: "+TopmenuUlFontSize+"px; font-weight: "+TopmenuUlFontWeight+"; text-align: "+TopmenuUlTextAlign+";";
changeRule("#topmenu ul",TM1);
It works for Firefox, but not for IE. I guess this is because addRule accepts one rule per command. How can I solve this problem?