Optional CSS templates on the same page
How would I have a page that loads with one CSS document, then when they click a box somewhere, the CSS file will change and the site will look different. I want to have the user be able to dynamically change the appearance of the site to different files i create, so they can pick the one they like best
Re: Optional CSS templates on the same page
Hi there damasterjo,
have a look at this example, it may suit your requirements...
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link id="styles" rel="stylesheet" type="text/css" href="style1.css">
<script type="text/javascript">
window.onload=function(){
document.getElementById('choice').onchange=function() {
document.getElementById('styles').href=this.value;
}
}
</script>
</head>
<body>
<div>
<select id="choice">
<option value="style1.css">style one</option>
<option value="style2.css">style two</option>
<option value="style3.css">style three</option>
<option value="style4.css">style four</option>
</select>
</div>
</body>
</html>
coothead
Re: Optional CSS templates on the same page
im sorry this dosent change the file when i choose an option, why not?
1 Attachment(s)
Re: Optional CSS templates on the same page
Hi there damasterjo,
Quote:
I'm sorry this doesn't change the file when I choose an option, why not?
Well, I can only assume that you are having problems with your coding. ;)
I have tested my code in IE6, IE7, Opera 9.27, Firefox 2 and Safari 3 with no problems.
The attachment contains this test for you to try at your leisure. :)