Mariano López wrote:
Hi. How can I make the following code (for Internet Explorer) work
fine on Netscape 6 and Opera?
document.createStyleSheet();
with (document.styleSheets(document.styleSheets.length-1)) {
addRule("A.newslink","text-decoration:"+FDRlnkDec+";color:"+
FDRlnkCol);
addRule("A.newslink:hover","color:"+ FDRhovCol);
}
AFAIK Opera doesn't provide a way to access the styleSheets collection.
To insert a rule in a stylesheet with Mozilla, use the insertRule method.
See the example.
document.createStyleSheet();
var myStyle=document.styleSheets(document.styleSheets. length-1)
// for IE
if(myStyle.addRule) {
myStyle.addRule("A.newslink","text-decoration:"+FDRlnkDec+";color:"+FDRlnkCol);
myStyle.addRule("A.newslink:hover","color:"+ FDRhovCol);}
// for Mozilla
else if(myStyle.insertRule){
myStyle.insertRule("A.newslink {text-decoration:"+FDRlnkDec+";color:"+FDRlnkCol+"}",0);
myStyle.insertRule("A.newslink:hover {color:"+ FDRhovCol")",0);}
The 2nd argument of the inserRule() method is the # of the rule, 0
means first. To insert the rule at the end of the stylesheet you may
use myStyle.cssRules.length instead of 0.
HTH
--
Y.D.