thilakg
thilakg

Reputation: 89

nested accordian menu not working properly

i need nested accordian menu so that i have followed this tutorial from this link. i have changed the jquery

$('li a').click(function (e) {
e.preventDefault();
var ullist = $(this).parent().children('ul:first');
ullist.slideToggle(); });

it is working but if i click child,parent can not be hide. can any one give me solution. please check this (http://jsfiddle.net/LgejL4oh/3/)

thank you

Upvotes: 0

Views: 90

Answers (1)

Runcorn
Runcorn

Reputation: 5224

Well I managed to make it work. I make it work by doing ,

First Check if the Element being clicked has child ul:first hidden or not.

  1. If visible skip the toggle functionality(Means you are toggling on/off the same tab)
  2. else toggle all the other visible element except the current one(So, If Company is previously visible hide it and display the current clicked tab )

So, Here is the code ,

if (!$(this).parent().children('ul:first').is(":visible")) {
    $(this).parent().parent().find("li").children('ul:visible').slideToggle();
 }
var ullist = $(this).parent().children('ul:first');
ullist.slideToggle();

And here is the working fiddle

Upvotes: 2

Related Questions