How to Show Bootstrap Dropdown Menu on Hover

Last Updated on January 13, 2021 by Roshan Parihar

In this tutorial, learn how to show Bootstrap dropdown menu on hover using jQuery or CSS. The short answer is: use the jQuery hover() with the addClass() to display the dropdown menu on mouse hover.

You can also use the jQuery removeClass() to hide the menu on mouse out. It requires to add/remove the class of Bootstrap to show/hide the dropdown menu on hover that you will learn below with examples.

Show and Hide Bootstrap Dropdown Menu on Hover Using jQuery

To perform an action on hover, you have to use the jQuery hover() function. On hover, you have to add a Bootstrap class .open using addClass() method. To close the menu on mouse out, you can use the jQuery removeClass() method as given in the example below:

Output

The above example contains the dropdown menu button that displays on mouse hover and hides on mouse out. You can take your mouse to the menu item to open the dropdown on hover. You can also check the ‘open’ class if it adds or removes a CSS class using jQuery.

If you want to open the dropdown menu on hover using only CSS and not jQuery, then read further to perform this task.

Display Menu on Mouseover Using CSS Only

Another way of showing the dropdown menu on mouse hover is by using CSS. You just need to add a few lines of CSS given below to perform this task. It selects the element on hover using :hover selector. After that, it uses the CSS property display:block on hover to display the dropdown menu on mouse hover. This requires less code and require no jQuery coding to achieve this task.

Output

When you mouseover over the above item, the dropdown menu items start displaying. It also hides the dropdown menu on the mouse out without any need for other CSS for this. So, an easy to use a method using CSS with fewer requirements of writing CSS codes.

You May Also Like to Read

I hope you like this tutorial on how to show the Bootstrap dropdown menu on hover using jQuery or CSS.