At the moment i have a stylesheet switcher which uses javascript to to load a new stylesheet based on a selection made in a dropdown menu.
I would like to re-write the code to use jQuery instead of javascript. Can anyone help me? I have had a look around for jQuery solutions, and although there are many, non utilise a dropdown menu. This is my code:
<head>
<link href="colour/light.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function changeScheme()
{ var _head = document.getElementsByTagName('head')[0];
var _link = document.createElement('link');
_link.type = 'text/css';
_link.href = colour.colour.options[colour.colour.selectedIndex].value;
_link.rel = 'stylesheet';
_head.appendChild(_link);
}
</script>
</head>
<body>
<form action="#" name="colour" id="colour" onsubmit="return false;">
<select name="colour" onchange="changeScheme();">
<option value="colour/light.css">Light scheme</option>
<option value="colour/dark.css">Dark scheme</option>
</select>
</form>
</body>
Thanks for the help!
1 Answer