I want to remove these Slide up function
$( document ).ready(function() {
$("#tabBar ul.buttons > li > a").on("click", function(e){
//if submenu is hidden, does not have active class
if(!$(this).hasClass("active")) {
// hide any open menus and remove active classes
$("#tabBar ul.buttons li ul").slideUp(350);
$("#tabBar ul.buttons li a").removeClass("active");
// open submenu and add the active class
$(this).next("ul").slideDown(350);
$(this).addClass("active");
//if submenu is visible
}else if($(this).hasClass("active")) {
//hide submenu and remove active class
$(this).removeClass("active");
$(this).next("ul").slideUp(350);
}
});
});
when i add another div to the body by Jquery
$(document).ready(function(){
$(".Collapse_menu").click(function(){
$(".bodyStatic").toggleClass("collapse-body");
//comment: here i want to add my code so that when i call collapse-body the top slide up function should remove
});
});
I am making a collapsable menu here are the images which helps you for better understanding
This is my try
if($(".bodyStatic").hasClass("collapse-body"))
{
//DO NOTHING
}
else
{
$(this).next("ul").slideUp(350);
}
//OR VICE VERSA
As per my understanding whenever you click
on .Collapse_menu
, you want to collapse the horizontally expanded menu as well as close the vertically opened submenu. If this is the case then you may want to try below code:
Code1:
$( document ).ready(function() {
$("#tabBar ul.buttons > li > a").on("click", function(e){
if($(".bodyStatic").hasClass("collapse-body"))
{
$(".bodyStatic").removeClass("collapse-body")
}
//if submenu is hidden, does not have active class
if(!$(this).hasClass("active")) {
// hide any open menus and remove active classes
$("#tabBar ul.buttons li ul").slideUp(350);
$("#tabBar ul.buttons li a").removeClass("active");
// open submenu and add the active class
$(this).next("ul").slideDown(350);
$(this).addClass("active");
//if submenu is visible
}else if($(this).hasClass("active")) {
//hide submenu and remove active class
$(this).removeClass("active");
$(this).next("ul").slideUp(350);
}
});
});
Code2:
$(document).ready(function(){
$(".Collapse_menu").click(function(){
$(".bodyStatic").toggleClass("collapse-body");
var activeSubmenu = $("#tabBar ul.buttons > li > a.active"); //grab the active submenu if any
//hide submenu and remove active class
$(activeSubmenu).removeClass("active");
$(activeSubmenu).next("ul").slideUp(350);
});
});
Please let me know the outcome.
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