Keeping A Jquery Menu Open With Cookies
I've been playing around with some of the jQuery cookies I've found across this site and the cookie I think is working but my menu stops opening altogether. I'm very new to jQuery
Solution 1:
Here's a little messier answer:
jQuery(function ($) {
// jQuery code in here can safely use $
$('.nav li')
.css({
cursor: "pointer"
});
$(".drop")
.on('click', function () {
$(this).toggleClass('open');
$(this).find('ul').toggle();
$.cookie('open_items', 'the_value');
openItems = newArray();
$("li.drop").each(function(index, item) {
if ($(item).hasClass('open')) {
openItems.push(index);
}
});
$.cookie('open_items', openItems.join(','));
});
if( $.cookie('open_items') && $.cookie('open_items').length > 0 ) {
previouslyOpenItems = $.cookie('open_items');
openItemIndexes = previouslyOpenItems.split(',');
$(openItemIndexes).each(function(index, item) {
$("li.drop").eq(item).addClass('open').find('ul').toggle();
});
}
});
You'll need to include the jquery.cookie library for this.
Updated fiddle can be found here: http://jsfiddle.net/pHgB7/2/
Post a Comment for "Keeping A Jquery Menu Open With Cookies"