css and javascript

M

Mariano López

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);
}



Thanks.
 
Y

YD

Mariano said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,077
Messages
2,570,566
Members
47,202
Latest member
misc.

Latest Threads

Top