Hi,

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.

This is the javascript that I have:

$(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!

Member Avatar for LastMitch

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.

I assume you got the code from here:

http://matthewaprice.com/simple-wordpress-accordion-menu/

It's a plugin:

http://wordpress.org/extend/plugins/jquery-vertical-accordion-menu/

WordPress has it own forum and if it's an plugin it also means it has a forum for that plugin too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.