Show/hide with cookies

Hi,

when i open news and refresh everything good, bu when i closed news and resfresh still show open news.

I try delete cookies with code: function del_cookie(name) { document.cookie = name + ‘=; expires=Thu, 01-Jan-70 00:00:01 GMT;’; }, but didin’t work.


<script type="text/javascript">
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
function del_cookie(name)
 { document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;'; }

function change(id){
     ID = document.getElementById(id);

     if(ID.style.display == "")
     {
          ID.style.display = "none";
          del_cookie("id");
     }
     else
          ID.style.display = "";
          createCookie("id",id,7); /* 1 week */
      }

window.onload = function() {
    try{change(readCookie("id"));}catch(e){} //rough example
};
</script>
<div>
<div onclick="change(5)" style="cursor: hand">
    <a href = "#">+</a>News
</div>
<div style="display: none" id="5">
    News1<br/>
    News2<br/>
</div>
<div onclick="change(4)" style="cursor: hand">
    <a href = "#">+</a>News2
</div>
<div style="display: none" id="4">
    News2 1<br/>
    News2 2<br/>
</div>
</div>

Your createCookie function is hard coded to set the path to ‘/’, so you must specify the same path when deleting.