0

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!

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by LastMitch
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.