Here is an implementation. It borrows much of the event handler logic from this post. YOU SHOULD NOT USE THIS CODE IN PRODUCTION. There is nothing worse than copying and pasting code you do not understand. Read and practice, when you fully understand this code you will be able to write a much better implementation that you will be able to maintain and support.
<link rel="stylesheet" type="text/css" href="style1.css" id="switch_style"/>
JS stuff:
<script type="text/javascript">
(function(){
function getEvent (e) {
if(!e) e = window.event;
if(e.srcElement) e.target = e.srcElement;
return e;
}
function addEvent (object,type,listener,param) {
if(object.addEventListener) {
object.addEventListener(type,
function(e){
listener.call(object, e, param);
},
false );
} else if(object.attachEvent) {
object.attachEvent('on'+type,
function(e){
e = getEvent(e);
listener.call(object, e, param);
}
);
}
}
var default_style = 1,
container = document.getElementById('switch_container'),
controls = container.childNodes,
styles = document.getElementById('switch_style');
function switch_style(event){
event = getEvent(event);
s = event.target.getAttribute('value');
styles.setAttribute('href, 'style' + s + '.css');
}
[].map.call(controls, function( e, i, l ){
if( e.nodeType === 1 && e.getAttribute('type') === 'radio' ) {
addEvent( e, 'click', switch_style );
}
})
// bind the function to the event handler.
})()
</script>
DOM stuff:
<div id="switch_container">
<input type="radio" name="switch" value="1"/>style 1<br/>
<input type="radio" name="switch" value="2"/>style 2<br/>
<input type="radio" name="switch" value="3"/>style 3<br/>
<input type="radio" name="switch" value="4"/>style 4<br/>
<input type="radio" name="switch" value="5"/>style 5<br/>
<input type="radio" name="switch" value="6"/>style 6<br/>
</div>
JSFIDDLE