Skip to content

Instantly share code, notes, and snippets.

@kylekeesling
Created January 18, 2013 19:50
Show Gist options
  • Save kylekeesling/4567862 to your computer and use it in GitHub Desktop.
Save kylekeesling/4567862 to your computer and use it in GitHub Desktop.
How to use the jQuery Cookie plugin
<!doctype html>
<html>
<head>
<title>Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<!-- Available here: https://github.com/carhartl/jquery-cookie -->
<script src="jquery.cookie.js"></script>
</head>
<body>
<script>
// This sets your cookie
$(document).ready(function() {
$.cookie('nameOfMyCoolCookie', 'CookieValue', { expires: 7 }); //Expires in 7 days
})
</script>
<script>
// This is how you use the cookie
$(document).ready(function() {
var myCookieValueInAVariable = $.cookie('nameOfMyCoolCookie');
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment