document.cookie = ‘name=Buffy; expires=Fri, 15 Dec 2020 23:00:00 GMT’; let myCookies = document.cookie; This command returns all cookies, meaning you’d have to manually extract the data you need. The code for updating a cookie is similar to the code for creating a new one—you simply overwrite the existing cookie with a new value. Let’s change the user’s name from “Buffy” to “Sabrina”: document.cookie = 'name='Sabrina'; expires=Fri, 15 Dec 2020 23:00:00 GMT'; To delete a cookie, you do the same thing again. This time, however, you should set expires to be a date in the past: document.cookie = 'name='Sabrina'; expires=Fri, 15 Dec 1970 10:00:00 GMT';
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter