How to set and unset cookies using jQuery? Last Updated : 01 Mar, 2023 Comments Improve Suggest changes Like Article Like Report An HTTP cookie is a small piece of data sent from a server and stored on client-side by the browser itself, Cookies are made to keep track of user and also to provide one nice browsing experience. We can also set our own cookies in the browser according to our need. Cookies can be set in the browser with the help of JavaScript or the jQuery. Here we will be seeing how to set cookies in the browser with the help of jQuery and how to remove them later on. Here we are using CDN of jQuery cookies to insert a cookie in the browser . Note: Please keep your internet connection on while using this code as it uses CDN services for jQuery. Example 1: Setting cookies in the browser after that we will remove that cookie. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Cookie | Geeksforgeeks</title> <script src= "https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin= "anonymous"></script> <script src= "https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script> </head> <body> <center> <h1 style="color: green">GeeksforGeeks</h1> <button onclick="addCookie()"> Add Cookie </button> <button onclick="removeCookie()"> remove Cookie </button> <p></p> <script> let addCookie=()=>{ $.cookie("geeksforgeeks", "It is the data of the cookie"); $("p").text("cookie added"); } let removeCookie=()=>{ $.removeCookie("geeksforgeeks", "It is the data of the cookie"); $("p").text("cookie removed"); } </script> </center> </body> </html> Output: You can clearly see there is a cookie named GeeksforGeeks with a value. We can also set the cookie Expiry date. Before adding Cookie: After adding Cookies: After removing Cookie: Comment More infoAdvertise with us Next Article How to set and unset cookies using jQuery? T tarun007 Follow Improve Article Tags : Web Technologies JQuery jQuery-Basics Similar Reads How to read write and delete cookies in jQuery? In this article, we will learn how to read, write and delete cookies in jQuery. This can be done using the cookie() and removeCookie() methods of the jquery-cookie library. We will first understand what exactly is a cookie.Cookie: Cookies are small blocks of data created by a web server when a user 3 min read How to Set & Retrieve Cookies using JavaScript ? In JavaScript, setting and retrieving the cookies is an important task for assessing small pieces of data on a user's browser. This cookie can be useful for storing user preferences, session information, and many more tasks. Table of Content Using document.cookieUsing js-cookie libraryUsing document 2 min read How to Clear all Cookies using JavaScript? Cookies allow clients and servers to exchange information via HTTP, enabling state management despite HTTP being a stateless protocol. When a server sends a response, it can pass data to the user's browser in the form of key-value pairs, which the browser stores as cookies. On subsequent requests to 2 min read How to Reset Form using jQuery with reset() Method? Reset a form means clear all input fields data and returns to their initial default values. It can be useful where a user wants to clear all entered data or you want to reset the form after a successful submission. The reset() method can easily reset the form data after clicking the reset button or 3 min read How to enable/disable a button using jQuery ? Enabling/disabling a button using jQuery involves altering its functionality to either accept user input or not. This is typically done by manipulating its 'disabled' property or attribute through jQuery methods like `.prop()` or .attr().To enable/disable a button using jQuery, you'll need a basic H 2 min read Like