/ Published in: jQuery
How to set, get, check for and remove cookies with jQuery.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//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);
URL: http://www.vagrantradio.com/2009/10/getting-and-setting-cookies-with-jquery.html