Skip to content

Instantly share code, notes, and snippets.

@ihorduchenko
Created September 7, 2017 13:35
Show Gist options
  • Save ihorduchenko/90d7c9c3fac3eec792e31faa7344da0a to your computer and use it in GitHub Desktop.
Save ihorduchenko/90d7c9c3fac3eec792e31faa7344da0a to your computer and use it in GitHub Desktop.
Hide dropdown block when click elsewhere
$(document).click(function (e) {
e.stopPropagation();
var container = $(".menu-item-has-children>a"); //Parent of dropdown block
//check if the clicked area is dropDown or not
if (container.has(e.target).length === 0) {
$('.menu-item-has-children .dropdown-menu').removeClass('d-block');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment