1

This was asked quite a few times before, but I can't find a proper solution yet. I am toggling navbar dropdown menus on hover with the following code:

$(".nav .dropdown").hover(function() {
  $(this).find(".dropdown-toggle").dropdown("toggle");
});

which works just fine. However, clicking on the .dropdown-toggle button toggles the menu as well, which I want to avoid. Any suggestions on the code?

3
  • can you make fiddle for issue? Commented Sep 23, 2015 at 9:31
  • one solution : stackoverflow.com/a/15698013/2269262 Commented Sep 23, 2015 at 9:33
  • $('.dropdown-toggle').on('click',function(e){ e.preventDefault()}); Commented Sep 23, 2015 at 9:42

1 Answer 1

2

Just stop the propagation here:

$('.dropdown-toggle').click(function(event){
     event.stopPropagation();
 });
Sign up to request clarification or add additional context in comments.

1 Comment

In bootstrap 4, the dropdown event is tied directly to the .dropdown-toggle div, so this unfortunately doesn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.