Stylesheet switcher using jQuery - toggle example

This is an extended version of my original stylesheet switcher for jQuery. It is slightly more fully featured than the original version (which was written back in 2006!) as it includes the option to toggle stylesheets (which will loop between the available stylesheets one after the other). It is also more reusable as you can now trigger the stylesheet switching from your own code.

Currently active stylesheet: styles1 styles2 styles3

Toggle between stylesheets.

Choose a specific different stylesheet:

Please also refer to the original code and view the source of stylesheetToggle.js to see how this version works. More information is also available in my blog announcement for this version.

Code

$(function()
	{
		// Call stylesheet init so that all stylesheet changing functions 
		// will work.
		$.stylesheetInit();
		
		// This code loops through the stylesheets when you click the link with 
		// an ID of "toggler" below.
		$('#toggler').bind(
			'click',
			function(e)
			{
				$.stylesheetToggle();
				return false;
			}
		);
		
		// When one of the styleswitch links is clicked then switch the stylesheet to
		// the one matching the value of that links rel attribute.
		$('.styleswitch').bind(
			'click',
			function(e)
			{
				$.stylesheetSwitch(this.getAttribute('rel'));
				return false;
			}
		);
	}
);