certainlyakey
3/23/2015 - 8:56 AM

jQuery - sidemenu close when clicking elsewhere

jQuery - sidemenu close when clicking elsewhere

$('html').click(function(event) {
	if ($(event.target).closest('.sidemenu, .menu-button').length === 0) {
		$('.sidemenu').removeClass('open');
	}
});

$('.menu-button').on('click', function(e) {
	if ($('.sidemenu').hasClass('open')) {
		$('.sidemenu').removeClass('open');
	} else {
		$('.sidemenu').addClass('open');
	}
});