When you create a session cookie it will continue to exist for as long as the browser remains open and will be deleted as soon as the browser is closed. This is because session cookies are actually retained in memory by the browser and are never actually stored anywhere. You do not specify an expiry date when creating a session cookie.
If you want a cookie to last for a longer (or shorter) time than you get wioth a session cookie you need to create a first party cookie instead. With a first party cookie the cookie is actually stored in a file on your visitor's hard drive. You specify an expiry date/time when creating a first party cookie that defines how long the cookie is to be retained on the hard drive. The cookie isn't necessarily deleted when that date/time is reached but cookies that have passed their expiry date/'time are ignored and so as far as the browser is concerned they don't exist.
So how does this help us if we decide that we need to delete a cookie befre the date/time that it is set to expire? Well the solution is quite simple, we change the expiry date of the cookie so that it will be considered to have already expired. Rather than having to remember what to do each time, let's just create a small function for deleting whichever cookie that we want.
document.cookie = name +
'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
Now all we need to do is to call this del_cookie() function passing it the name of whatever cookie it is that we wish to delete. The function will update the expiry date on the cookie to one long in the past so that the cookie will be considered to be expired and will be ignored by the browser exactly the same as if it didn't exist.