So far I have this drop-down menu . When I click on either "Menu", "Menu1" or "Menu2", the links under it will drop down.
The problem: I need to display only one drop-down at a time, so that the user can switch between them.
I tried to apply css('overflow', 'hidden');
to the menu currently dropped down, but it won't work, since the overflow: visible !important;
is applied to the .clicked
class. Please help, anything will be highly appreciated!
Try when you click on a element remove class clicked
from all elements and add class clicked
to the element that is clicked
$("#product-menu>ul>li").click(function () {
var hidden = $(this).find('.clicked');
$("#product-menu>ul>li").removeClass('clicked');
$(this).addClass('clicked');
$('.productSubmenu').width(menuWidth);
});
UPDATE
If you want also on second click menu to be closed try checking if clicked item has already class clicked
:
$("#product-menu>ul>li").click(function () {
var hidden = $(this).find('.clicked');
if ($(this).hasClass('clicked')) {
$(this).removeClass('clicked')
} else {
$("#product-menu>ul>li").removeClass('clicked');
$(this).addClass('clicked');
}
$('.productSubmenu').width(menuWidth);
});
You also might want to close the links
$("#product-menu>ul>li").click(function () {
var hidden = $(this).find('.clicked');
$("#product-menu>ul>li").removeClass('clicked');
$("#product-menu .productSubmenu2").hide(); // this one I added
$(this).addClass('clicked');
$('.productSubmenu').width(menuWidth);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.