Open one class, close others
I have written a little list menu with expandable categories using this little piece of jQuery
$("#menu ul li ul").hide();
$("#menu ul li").click(function() {
$(this).find("ul").slideToggle();
});
There is a full jsFiddle of the menu here: http://jsfiddle.net/AlexSadler/uRwh7/7/
The only problem is that when one category is open and I go to open another, the first one doesn't close and I end up running out of space. Does anybody know ho开发者_开发百科w I could rectify this?
$('#menu ul li').click(function() {
$(this)
.find('ul')
.slideToggle()
.end()
.parent()
.siblings()
.find('li ul')
.hide()
;
});
Try this code,
$("#menu ul li ul").hide();
$("#menu ul li").click(function() {
$("#menu ul li ul").hide();
$(this).find("ul").slideToggle();
});
精彩评论