I have a slideDown menu and I want to remember the last state of the menu so that on page load the last state is already selected. I am trying to accomplish this by using jQuery.cookie and this is what i did:
$("#menu h3").click(function(){
$("#menu ul ul").slideUp();
if(!$(this).next().is(":visible")){
var id = $(this).attr('id');
$.cookie(id, $(this).is(':visible') ? "closed" : "open");
if ($.cookie(id) == "open") {
$(this).next().slideDown();
}
}
});
>> jsFiddle <<
When I reload the page I don't get the last state and .slideDown()
doesn't work.
Can anyone help me?
Thanks!
I modified your code a little. Try this:
Make sure you also set ids for your
h3
elements.Demo http://jsfiddle.net/K4pUV/1/