Dynamically changing a stylesheet

W

wjbell

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;
}
}
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top