Here's my code: UPDATED JS
jQuery(document).ready(function()
{
var cookieName = 'activeMenus';
var openMenus = (jQuery.cookie(cookieName) == null) ? 0 : jQuery.cookie(cookieName).substring(1).split(',');
var wookie = '';
jQuery('ul.menu li ul').css('display', 'none');
// Reopen all the menus from the cookie
if (openMenus != 0)
{
for (var i = 0; i < openMenus.length; i++)
{
alert('Opening: ' + openMenus[i]);
jQuery('ul.menu li').children('ul').eq(openMenus[i]).css('display', 'block');
}
}
// Hide the menu upon click and modify the cookie
jQuery('ul.menu span.topdaddy span').click(function()
{
// Toggle the menu for the clicked link
jQuery(this).parents('li').find('ul').slideToggle('slow', function()
{
// Once the menu has been toggled - Find all the open menus
jQuery('ul.menu li').children('ul:visible').each(function()
{
wookie += ',' + jQuery(this).index(); // Build the index list
jQuery.cookie(cookieName, wookie);
});
});
wookie = '';
});
});
HTML
<ul class="menu">
<li class="item1">
<a href="#"><span>Link 1</span></a>
</li>
<li class="parent item55">
<span class="topdaddy"><span>Link 2</span></span>
<ul>
<li class="item62">
<a href="#"><span>Link 3</span></a>
</li>
<li class="item63">
<a href="#"><span>Link 4</span></a>
</li>
</ul>
</li>
<li class="parent item56">
<span class="topdaddy"><span>Link 5</span></span>
<ul>
<li class="item69">
<a href="#"><span>Link 6</span></a>
</li>
<li class="parent item70">
<ul>
<li>asdasd</li>
</ul>
</li>
</ul>
</li
</ul>
It's a menu system that uses cookies to remembers the currently opened menus to reopen those menus each page load.
The code works... But it's a little buggy.
The .eq() call is opening index 2 rather than 1. They're both supposed to be 0-based indexes, so I see no reason why it should be doing this.
Any ideas?