Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question css and javascript

    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.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    DOM 2 CSS - check out this thread http://codingforums.com/showthread.p...threadid=18442

    Won't be for Opera though; moz only.
    Last edited by brothercake; 07-17-2003 at 10:12 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #3
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, this is the code I've created...

    Code:
    function loadss() {
      var r = false;
    
      if (document.createStyleSheet) { 
        // THIS CODE IS FOR IE ONLY, AND WORKS FINE
        with (document.createStyleSheet()) {
          addRule("P","font-family: verdana; font-size: 10pt; color: red");		
        }	
        r = true;
      }
      else if (document.getElementsByTagName && document.createElement) {
        // THIS CODE IS FOR NS6 AND OPERA, BUT DOESN'T WORK
        var head = document.getElementsByTagName("head")[0];
    		
        if (!head || !head.appendChild) {
          r = false;
          return;
        }
    
        var mystyle = document.createElement("style");
        mystyle.type = "text/css";
        mystyle = head.appendChild(mystyle);
    
        var myStyleSheet = document.styleSheets.item(document.styleSheets.length-1);
        myStyleSheet.insertRule("P {font-family: verdana; font-size: 10pt; color: red}", myStyleSheet.cssRules.length);
    	
        r = true;
      }
    }
    
    Netscape 6 complains at myStyleSheet.insertRule, it says "Error: myStyleSheet has no properties".
    Opera 7 says "Expression evaluated to null or undefined and is not convertible to Object: document.styleSheets - var myStyleSheet = document.styleSheets.item(document.styleSheets.length - 1);"
    What can I do?
    Last edited by lopardo2003; 07-18-2003 at 12:45 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •