UPDATED to close menu if clicked outside of clicker_class
elements.
You can track the state of the show_menu_users
using a boolean. When you click on the clicker_class
elements, toggle the menu and update the boolean. When you click elsewhere in teh document, close the menu.
(function ($) {
$(document).ready(function () {
var isShowing = false;
var toggleMenu = function() {
isShowing = !isShowing; //change boolean to reflect state change
$('.show_menu_users').toggle(isShowing); //show or hide element
}
$(document).on('click', function (e) {
if($(e.target).is('.clicker_class') || $(".clicker_class").has(e.target).length !== 0) {
toggleMenu();
} else {
isShowing = false;
$('.show_menu_users').hide();
}
});
});
})(jQuery);