The HTTP cookies is mainly used to send a small piece of data from a website and store it in a user's web browser. From this blog you will learn how to set the value in the cookies and getting the stored value from it using Jquery Plugin called js-cookie
js-cookie is a Jquery plugin which makes life easier to get and set the values for cookies.
Get the Js-cookie plugin from
here.
Example
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <script src="https://code.jquery.com/jquery-3.1.0.min.js" ></script>
- <script src="Script/js.cookie.js"></script>
-
- <meta charset="utf-8" />
- </head>
- <body>
- <label id="lblcookie" style="font-family:Arial;font-style:italic;color:orange"></label>
- </body>
-
- </html>
- <script>
- $(document).ready(function()
- {
-
- Cookies.set('Message', 'Hello C-Sharp Corner')//set the cookie value
- var CookieValue=Cookies.get('Message')//get the value from cookie
- $("#lblcookie").text(CookieValue);
- })
- </script>
Set the Cookie
Cookie.set('[name/key of the cookie]','Value of the Cookie ')
Get the Cookie
Cookie.get('[name/key of the cookie]')
Output