hsquareweb
8/27/2013 - 3:57 PM

JS: Cookie

JS: Cookie

// Include script after the jQuery library
// https://github.com/carhartl/jquery-cookie
// <script src="/path/to/jquery.cookie.js"></script>

//set cookies
$("#div").toggle(function() { //create div toggle
	$("#div").slideUp("slow"); //create effect
	$.cookie('cookie_name', 'value', {expires: 7}); //set cookie expire in 7 days
}, 
function () { //continue the toggle
	$("#div").slideDown("slow"); //create effect
	$.cookie('cookie_name', 'value'); //set cookie
});
 
//get cookie
alert( $.cookie("cookie_name") );
 
//check for cookies
	var cookie_name = $.cookie('cookie_name'); //set cookie var
	if (cookie_name == 'value') { //if equals this val
		$("#div").hide(); //do this
	};
 
//check for null cookies
var cookie_name = $.cookie('cookie_name'); //set cookie var
	if (cookie_name == null) { // if empty
		$("#div").hide(); //do this
	};
 
//null cookies, same as getting
$.cookie("cookie_name", null);