I want to delete browser cookie when a button clicked. I have checked my code and found that onclick
event working and execute the deleteCookie
function but cookie not deleted.
Below is my code:
$(".close-conversation").on("click", function (e) {
e.preventDefault();
console.log('button clicked');
deleteCookie('instanceId');
deleteCookie('chatWindow');
deleteCookie('userdataLoaded');
});
//deleteCookie function
function deleteCookie(cname) {
document.cookie = cname + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
console.log('cookie deleted')
}
please help me to find the mistake. Thanks in advance.