I am working on a customized bootstrap dropdown menu that needs to remain open when the search bar within the Events dropdown is focused. I have managed to make it open and close on hover, but now I need it to stay open under certain conditions.
Below is my JavaScript code:
$('ul.nav li.dropdown').hover(function() {
$(this).closest('.dropdown-menu').show(); $(this).addClass('open'); },
function() {
$("#search-query").focusin(function() {
$('.events').addClass('search-active');
});
if ($('.events').hasClass('search-active')) {
return;
} else {
$(this).closest('.dropdown-menu').hide(); $(this).removeClass('open');
}
});
You can view the complete code on this Codepen link: http://codepen.io/webinsation/pen/bfDsB
Despite trying various methods using jQuery's ':focus' selector, I haven't been able to achieve the desired outcome. If you have any suggestions or ideas, please feel free to share them. Thanks, – Caleb