I have a WordPress menu with a dropdown. I have CSS code to underline the selected menu item when it is active. This works for both root level menu items and sub-menu items. I would like to do is set the dropdown to active when one of the sub-menu items is clicked. I'm trying this in jQuery.
jQuery(function($) {
$(".navbar .nav .nav-item.dropdown li").click(function() {
$(".navbar .nav .nav-item.dropdown").addClass('active');
});
}
It almost works. When I click the sub-menu item, I can see the dropdown go active, but then it goes right back to not active. I think that's happening is the jQuery fires and sets the dropdown to active and then the page reloads and that active is wiped out.
Any idea how I can make it stick?