I'm struggling with a problem here. I have two elements. One is a button and other is a menu. I need to solve a problem which occurs to me when I click on the button first time, menu opens, but when I click second time it doesn't. And when I click outside the menu it closes (that's good!). SO I need the element to close/open on click's with a button and clicking outside the element.
Here's my code:
$(".left-menu-block-one").click(function () {
$("#first-bar").toggleClass("show");
if ($("#second-bar").hasClass("show") || $("#third-bar").hasClass("show")) {
$("#second-bar").removeClass("show");
$("#third-bar").removeClass("show");
}
$(".left-menu-block-one").toggleClass("hide-menu-bars");
if ($("#first-bar").hasClass("show")) {
$(".left-menu-block-two").addClass("hide-menu-bars");
$(".left-menu-block-three").addClass("hide-menu-bars");
}
})
var container2 = $("#first-bar");
if (!container2.is(e.target) && container2.has(e.target).length === 0)
{
$("#first-bar").removeClass("show");
$(".left-menu-block-one").addClass("hide-menu-bars");
}
P.S. I added all code for those 2 elements, because maybe there is a problem with them...