0

I am working with it for an hour but I can't figure out what is wrong in that.

<html>

<body>

    <input type="button" value="set" onclick=setcook()>
    <input type="button" value="get" onclick=getcook()>

    <script>
        function setcook() {
            document.cookie = "un=nu";
        }

        function getcook() {
            if (document.cookie.length != 0)
                alert(document.cookie);
            else {
                alert("cookie not available");
            }
        }
    </script>

</body>

</html>
Roy
  • 7,811
  • 4
  • 24
  • 47
Pawandeep
  • 33
  • 1
  • 8
  • Does this answer your question? [How do I create and read a value from cookie?](https://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie) – ttrasn Dec 25 '19 at 08:01
  • 1
    seems to work OK. You know that to observe the effect you need to reload the page? – Professor Abronsius Dec 25 '19 at 08:12

1 Answers1

1

use this method.. hope it will help you

Cookies.set('key',value);