jquery .cookie plugin help

Soldato
Joined
12 May 2007
Posts
3,896
Location
Bristol
Anyone have experience with the jquery cookie plugin?
I've created a simple theme switcher but need to set a cookie to remember which theme should be used on the other pages.

Code:
	$("ul#themes li:first-child a").addClass('active');
	$("ul#themes li a").click(function(){
		$("ul#themes li a").removeClass('active');
		$(this).addClass('active');
		var theme = $(this).attr("id");
		$("link#themeswitch").attr("href", "media/css/" + theme + ".css");
		return false;
	});

This is the line which sets the CSS.
$("link#themeswitch").attr("href", "media/css/" + theme + ".css");

So how would I set a cookie to recall whatever my theme variable is and then apply it?
 
Once you've got the plugin, it's just a one liner to get/set

Code:
$.cookie("MyCookieName"); // GET
$.cookie("MyCookieName", "Value"); // SET

In your example you'd add the set to the click function. The get would go in the document load to specify the right stylesheet for rendering.
 
Back
Top Bottom