css and javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mariano López

    css and javascript


    Hi. How can I make the following code (for Internet Explorer) work fine on Netscape 6 and Opera?

    document.create StyleSheet();

    with (document.style Sheets(document .styleSheets.le ngth-1)) {
    addRule("A.news link","text-decoration:"+FD RlnkDec+";color :"+ FDRlnkCol);
    addRule("A.news link:hover","co lor:"+ FDRhovCol);
    }



    Thanks.

  • YD

    #2
    Re: css and javascript

    Mariano López wrote:[color=blue]
    > Hi. How can I make the following code (for Internet Explorer) work
    > fine on Netscape 6 and Opera?
    >
    > document.create StyleSheet();
    >
    > with (document.style Sheets(document .styleSheets.le ngth-1)) {
    > addRule("A.news link","text-decoration:"+FD RlnkDec+";color :"+
    > FDRlnkCol);
    > addRule("A.news link:hover","co lor:"+ FDRhovCol);
    > }[/color]

    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.create StyleSheet();
    var myStyle=documen t.styleSheets(d ocument.styleSh eets.length-1)
    // for IE
    if(myStyle.addR ule) {
    myStyle.addRule ("A.newslink"," text-decoration:"+FD RlnkDec+";color :"+FDRlnkCol );
    myStyle.addRule ("A.newslink:ho ver","color:"+ FDRhovCol);}
    // for Mozilla
    else if(myStyle.inse rtRule){
    myStyle.insertR ule("A.newslink {text-decoration:"+FD RlnkDec+";color :"+FDRlnkCol+"} ",0);
    myStyle.insertR ule("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.cssRule s.length instead of 0.

    HTH
    --
    Y.D.


    Comment

    Working...