I'm creating a responsive menu and I'm working on a function that close the menu when a user click outside it, so when a user click any other part of website ( of course, if the menu is open ). All seems to be very easy and there are 2 functions:
1st) Close the menu when any part of html is clicked
$('html').click(function () {
if (jQuery("#responsive_header").hasClass("tvda_header responsive")) {
document.getElementById("responsive_header").className = "tvda_header";
}
});
2nd) Open the menu when the menu's button is clicked
$('#h_r3').click(function () {
var x = document.getElementById("responsive_header");
if (x.className === "tvda_header") { x.className += " responsive"; }
});
Both functions work but there is a conflict between it. When I click the button to open the menu (div id="h_r3") the div class "tvda_header" change to "tvda_header responsive" and is detected by 1st function that of course change it again to "tvda_header" by removing the "responsive" class.
I try to change the order of functions or to run the 2nd after the first by using trigger but without success.
Any suggestion?