Dynamically changing a stylesheet

Discussion in 'Javascript' started by wjbell, Dec 11, 2003.

  1. wjbell

    wjbell Guest

    I have a piece of javascript I need to modify. Right now it changes a
    stylesheet in the document between style.css and no_indent.css. These
    are in the head of my document:

    <link rel=stylesheet href=/style.css>
    <link rel=stylesheet href=/no_indent.css>
    <link rel=stylesheet href=/style.css>


    What the code below does is toggle between the two depending on what
    link is clicked. Here are the links:

    <a href=JavaScript:changeSheets(1)>Threaded</a>
    <a href=JavaScript:changeSheets(2)>Flat</a>

    What I want to do is have one link that will toggle between the two
    stylesheets. So the page loads style.css initially. If the link is
    clicked once it changes to no_indent.css. If it's clicked again it
    changes back to style.css, and so on.

    Can anyone let me know how to do this?

    TIA

    code:
    ----------------------------------

    function changeSheets(whichSheet){
    whichSheet=whichSheet-1;
    if(document.styleSheets){
    var c=document.styleSheets.length;
    for(var i=0;i<c;i++){
    if(i!=whichSheet){
    document.styleSheets.disabled=true;
    }else{
    document.styleSheets.disabled=false;
    }
    }
    }
    }
    wjbell, Dec 11, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Valerian John

    Changing stylesheet

    Valerian John, Aug 22, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    395
    Jerry III
    Aug 22, 2003
  2. =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=

    Stylesheet referanse i stylesheet

    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=, Jul 3, 2004, in forum: XML
    Replies:
    3
    Views:
    563
    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=
    Jul 4, 2004
  3. Steven An
    Replies:
    1
    Views:
    493
    Martin Honnen
    Nov 23, 2004
  4. David Blickstein
    Replies:
    3
    Views:
    1,026
    David Blickstein
    Aug 2, 2005
  5. David Blickstein
    Replies:
    14
    Views:
    6,311
    Harrie
    Oct 16, 2005
Loading...

Share This Page