How to delete cookies with JavaScript

There is no delete function for cookies. You have to set it in the past.

Here's a function to do just that, set a cookie by its name in the past.

function delete_cookie(name) { document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;'; }

You might also need to add the domain in certain scenarios:

function delete_cookie(name) { document.cookie = name +'=; Path=/;; Expires=Thu, 01 Jan 1970 00:00:01 GMT;'; }

About Ricard Torres

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast

Leave a Reply

Add <code> Some Code </code> by using this tags.