I have an accordion menu for wordpress that works nearly the way I would like it to. I was wondering if there's a way to make the menu close once clicked again. I'm happy with how it opens when clicked, it just stays open after that and can't be closed by clicking again.
$(document).ready( function($) {
// This hides all the sub menus on page load
$('#nav-main ul.sub-menu').hide();
// This makes sure that all the sub menus are open when applicable
$('#nav-main li.current-menu-item').children().show();
// This keeps the nav open to the item that you are navigating to.
$('#nav-main li.current-menu-item').parents().show();
$('#nav-main ul li a').click(
function() {
var checkElement = $(this).next();
if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
return false;
}
if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
$(this).parent().siblings("li:has(ul)").find("ul").slideUp('normal');
$('#nav-main ul ul li ul:visible').slideUp('normal');
checkElement.slideDown('normal');
return false;
}
}
);
$('#nav-main ul ul li a').click(
function() {
var checkElement = $(this).next();
if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
return false;
}
if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
$('#nav-main ul ul').slideUp('normal');
$('#nav-main ul ul li ul:visible').slideUp('normal');
checkElement.slideDown('normal');
return false;
}
}
);
});
Appreciate any help!

New Topic/Question
Reply


MultiQuote




|