Skip to content

Instantly share code, notes, and snippets.

@haydenjameslee
Created June 28, 2014 19:34
Show Gist options
  • Save haydenjameslee/f016f097005a2d1d9a44 to your computer and use it in GitHub Desktop.
Save haydenjameslee/f016f097005a2d1d9a44 to your computer and use it in GitHub Desktop.
Bootstrap keep parent menu item highlighted when viewing its dropdown
var initDropdownHover = function () {
// Add class to parent on mouseenter
$('.dropdown-menu').mouseenter(function() {
// If already active then don't do anythin
if (!$(this).hasClass('active')) {
// Get menu parent and add active class
var parent = $(this).closest('li.dropdown')
parent.addClass('active');
// Remove added class
$('.dropdown-menu').mouseleave(function() {
parent.removeClass('active');
});
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment