I have created a Mega Menu, and I am not proficient in javascript/jquery. I have applied .slideToggle to bring out the dropdown on click. I want to close the first drop-down automatically if someone clicks on the second drop-down while bringing the 2nd drop-down. I tried Google before asking here. Below is the script I used as well as the link to Codepen.
Codepen link for Mega Menu
Any help would be appreciated. Thanks a ton in advance.
$(function(){
$(".about").click(function(){
$(".mainSub").slideToggle("slow");
$(".one").toggleClass("aboutClick");
})
$(".hf").click(function(){
$(".hfnav").slideToggle("slow");
$(".two").toggleClass("aboutClick");
})
$(".cntct").click(function(){
$(".three").toggleClass("aboutClick");
})
})
Edit: I want the About Us drop-down to close if someone clicks on Housing Finance, and the content of Housing finance drop-down should come up.
I think based on your codepen link, you're looking for
$(function(){
$(".about").click(function(){
$(".mainSub").slideToggle("slow");
$('.mainNavSub>*').removeClass('aboutClick');
$(".one").addClass("aboutClick");
});
$(".hf").click(function(){
$(".hfnav").slideToggle("slow");
$('.mainNavSub>*').removeClass('aboutClick');
$(".two").addClass("aboutClick");
});
$(".cntct").click(function(){
$('.mainNavSub>*').removeClass('aboutClick');
$(".three").addClass("aboutClick");
});
});
It removes the class from the other objects and adds the class to the current object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With