Clicking on the button opens a menu. When you click outside the menu, it closes. When you click on the button, the hamburger menu should also be closed if it is open. But I get to re-open the menu immediately after closing, and it does not close. How to make a close when clicking outside the menu, as well as when clicking on a button, if the menu is open?
$(".menu_btn").click(function() { if (!$("header").hasClass("open_menu")) { $("header").addClass("open_menu"); } }); $(document).mouseup(function(e) { var $target = $(e.target); if ($target.closest("nav").length === 0) { $("header").removeClass("open_menu"); } });