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 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question changing class attributes

    Ok, the problem, I need to change dynamically how a class is displayed, my site (with out going into detail) interprets saved info from the user (its saved through perl) in a *.js file, then views it through template *.htm files drawing on js files after loading.

    The thing is I need to allow for several settings like font type size and color, (things that could be held in style sheets) but then save in their js file a number representing this and load it when the template page is opened.

    I have two possibilities to answer this

    1, instead of using classes I could use Ids - but using 1 id for what could (hypothetically) be an endless string of elements seems real messy, I don't even know if it would work.

    2, I read somewhere I could dynamically generate style tags with the classes defined, but I can't find where I read this...

    Any help would be appreciated thanks.
    corrie track

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why not just use a cookie to store the style values, then on page load read the cookie and set the style properties accordingly.

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Getting the info loaded is not the problem, I'm actually using a cookie to store user vars to reference there personal *.js file, and pass info to validate the cgi - that part is working fine. Its just that after the template 'to view data' page is loaded and after its loaded their generated *.js file I have a bunch of variables that represents settings how do I access a class and change its settings to these variables?
    corrie track

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, when you say class you mean CSS class.

    Uhhhh, you don't.

    You can switch to a different style sheet (e.g. www.meyerweb.com) or actively change style properties on specific objects (like a rollover ) but you can't affect the class per-se. (that I know of)

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can access the individual rules in style sheets. This code changes the font-size property in the first rule of the second stylesheet in a document:

    Code:
      // DOM-compliant browsers.
    
      if (document.styleSheets[1].cssRules) {
        document.styleSheets[1].cssRules[0].style.fontSize = "16pt";
    
        // For NS 6.1, insert a dummy rule to force styles to be reapplied.
    
        if (navigator.userAgent.indexOf("Netscape6/6.1") >= 0)
          document.styleSheets[1].insertRule(null, document.styleSheets[1].cssRules.length);
      }
    
      // IE browsers.
    
      else if (document.styleSheets[1].rules[0])
        document.styleSheets[1].rules[0].style.fontSize = "16pt";
    A couple of notes: IE uses the property name .rules instead of .cssRules. NS 6.1 is a little buggy, it doesn't update the display when you change the style. The code above shows a workaround that makes it redraw the page. This bug doesn't seem to affect 6.0 or 6.2 however.

  • #6
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cool! Thanks BrainJar. I didn't realize each rule was exposed that way. thx


  •  

    Posting Permissions

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