How to set multiple cookies in JavaScript?

JavascriptWeb DevelopmentFront End Technology

With JavaScript, to set more than one cookie, set document.cookie more than once using the; separator.


You can try to run the following code to set multiple cookies −

Live Demo

<!DOCTYPE html>
      var num=1;
      function addCookie() {
      function listCookies() {
         var result = document.cookie;
      function removeCookies() {
         var res = document.cookie;
         var multiple = res.split(";");
         for(var i=0;i<multiple.length;i++) {
            var key = multiple[i].split("=");
            document.cookie=key[0]+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
      <button onclick='addCookie()'>ADD</button><br>
      <button onclick='listCookies()'>LIST COOKIES</button><br>
      <button onclick='removeCookies()'>REMOVE</button>
      <h1>Cookies List</h1>
      <p id="list"></p>
Updated on 16-Jun-2020 11:59:40