If your looking to enhance the experience of your visitors by offering them the ability of changing the layout and or colours on your webpage then this jQuery snippet could be handy for you.
With the use of cookies or even better the new HTML5 local storage feature the users preferences will be saved on there computer.
Using local storage is easier to code and quicker than using php and cookies and remember that’s what jQuery is all about “Write Less, Do More”.
Remove stylesheet
To remove a stylesheet simply give it an id
<link href=”cssFolder/sheet2.css” rel=”stylesheet” type=”text/css” id=”sheet2″>
And insert the following script just before </body> tag
<script type="text/javascript">
$(document).ready(function () {
jQuery('#sheet2').remove();
});
</script>
Add stylesheet
To Add a stylesheet insert the following script just before </body> tag
<script type="text/javascript">
$(document).ready(function () {
$('head').append('<link href="cssFolder/sheet2.css" rel="stylesheet" id="banSheet" />');
});
</script>
Although i have used document ready in the snippets above i have used the click function in the 2 demo files just to give you an idea of what can be done.
Bored?
Have a go yourself at designing a simple colour changer or text re-sizer for your page.


Hey Ian,
This is extremely close to the type of thing I’m looking for. I’m looking to be able to add a stylesheet, but instead of having one already created and just hitting a button to switch them out, I’m looking to be able to paste in a link to any external style sheet and clicking a submit button and have it use that style sheet. Do you know how the code could be modified to do that?
Hey Jason,
Sure please see the example i have done for you which loads the remote CSS file on press of a button
All the best,
Ian