By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,380 Members | 1,646 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,380 IT Pros & Developers. It's quick & easy.

css and javascript

P: n/a

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.

Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
YD
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.
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.