Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid having to double-click to toggle Bootstrap dropdown

I am using a Bootstrap dropdown menu. The problem is that it never drops down upon the first click; I need to click 2 times for it to be toggled. I guess the click event is somehow getting stuck somewhere before propagating down...

Is there any way to fix that?

like image 489
Jago Avatar asked Jun 14 '14 09:06

Jago


People also ask

How do I keep my Bootstrap dropdown open?

Just wrap the contents of the menu in a form tag. That's it.

How do you prevent the dropdown from closing by clicking inside?

As all Twitter Bootstrap users know, the dropdown menu closes on click (even clicking inside it). To avoid this, I can easily attach a click event handler on the dropdown menu and simply add the famous event. stopPropagation() .

How do you open Bootstrap dropdown menu on hover rather than click?

Answer: Use the jQuery hover() method By default, to open or display the dropdown menu in Bootstrap you have to click on the trigger element. However, if you want to show the dropdown on mouseover instead of click you can do it with little customization using the CSS and jQuery.

Why dropdown Bootstrap is not working?

Solution : The dropdown should be toggled via data attributes or using javascript. In the above program, we have forgotten to add a data attribute so the dropdown is not working. So add data-bs-toggle="dropdown" to toggle the dropdown.


1 Answers

If someone is using angular with ui-bootstrap module along with normal bootstrap HTML dropdown definition, there are also two clicks needed.

<li class="dropdown">    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>    [...] </li> 

=> Removing the data-toggle="dropdown" will fix the issue.

Opening the dropdown with one click will work after this.

Reference: https://github.com/angular-ui/bootstrap/issues/2294

like image 64
minni Avatar answered Sep 19 '22 07:09

minni