I have jquery menu with accordion and toggle effect. But it works with bugs: sometimes it closes all elements.
Can you help to do it best?
HTML:
<ul id="accordion">
<li>
<a href="#">Level 1</a>
<ul>
<li><a href="#">11</a></li>
<li><a href="#">12</a></li>
</ul>
</li>
<li>
<a href="#">Level 2</a>
<ul style="display: none;">
<li><a href="#">21</a></li>
<li><a href="#">22</a></li>
</ul>
</li>
</ul>
JS:
var sel = '#accordion'
$(sel + ' li a').toggle(
function() {
var checkElement = $(this).next();
if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
return false;
}
if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
$(sel + ' ul:visible').slideUp('normal').removeClass('selected');
checkElement.addClass('selected').slideDown('normal', function() {
});
return false;
}
},
function() {
$(sel + ' ul:visible').removeClass('selected').slideUp('normal', function() {
});
}
);
i looked over your code and I am not sure toggle is the best function for what you are trying to do, as I understand it.
I changed
toggletoclickand I changed your logic just a little.the javascript looks like this now:
With this javascript I was able to get the menus to go up and down with no quirky behavior.
fiddle