Add it to the callback of slideToggle()
instead:
$("ul#nav-Expanded").slideToggle(function() {
var isVisible = $('ul#nav-Expanded').is(':visible').toString();
$.cookie('nav-expanded', isVisible);
});
It doesn't work because .is(':visible')
isn't set while the menu is still sliding out and $.cookie()
is set to the initial state of isVisible
instead.