Skip to content

Instantly share code, notes, and snippets.

@goncharov
Created November 6, 2014 09:36
Show Gist options
  • Save goncharov/49a01307aeea79cd32c3 to your computer and use it in GitHub Desktop.
Save goncharov/49a01307aeea79cd32c3 to your computer and use it in GitHub Desktop.
// HEADER DROPDOWN MENUS
// Close dd on click if active
$('.shortcuts dl').click(function(e) {
if ($(this).hasClass('active')) {
$('.shortcuts dl').removeClass('active');
$('.shortcuts dl dt > span').removeClass('opened');
$(this).children('dd').hide();
}
// Open dd on click if not active
else {
$('.shortcuts dl').removeClass('active');
$('.shortcuts dl dt > span').removeClass('opened');
$('.shortcuts dl').children('dd').hide();
$(this).children('dd').show();
$(this).find('dt > span').addClass('opened');
$(this).addClass('active');
}
e.stopPropagation();
});
// Don't close dd when clicked on dd element
$('.shortcuts dl dd').click(function(e) {
e.stopPropagation();
});
// Close dd when clicked outside
$(document).click(function() {
$(".shortcuts dl dd").hide();
$('.shortcuts dl').removeClass('active');
$('.shortcuts dl dt > span').removeClass('opened');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment