Setting and Getting Cookies in jQuery
In this tutorial, we are going to use a jQuery library called jquery.cookie.min.js so that we can access cookies like this: $.cookie(‘name’)
Set a cookie:
1 2 3 4 5 6 7 | <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script> <script type="text/javascript"> jQuery(document).ready(function($){ $.cookie('cname', 'cvalue', { path: '/', expires: 1 }); }); </script> |
Retrieve the cookie:
1 | $.cookie("cname") |
Do you need help with a project? or have a new project in mind that you need help with?
Contact Me