
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
Bootstrap dropdown closing when clicked in HTML
As you may have seen, whenever you open a dropdown, and click anywhere else, the dropdown close.
By using the below given code, the dropdown menu can be kept open after click−
$('#myDropdown').on('hide.bs.dropdown', function () { return false; });
Another option is to handle the clickevent −
The click event can also be handled byusing the following code. The event.stopPropagation() method stopsthe bubbling of an event to parent elements. It prevents any parentevent handlers from being executed −
$('#myDropdown .dropdown-menu').on({ "click":function(e) { e.stopPropagation(); } });
- Related Articles
- How to prevent a dialog from closing when a button is clicked?
- How to prevent a dialog from closing when a button is clicked using Kotlin?
- Add a fading effect when closing an alert box in Bootstrap
- Bootstrap dropdown class
- Execute a script when the element is being clicked in HTML?
- Execute a script when the element is being double-clicked in HTML?
- Bootstrap class dropdown-header
- Execute a script when a reset button in a form is clicked in HTML?
- Create Dropdown menu with Bootstrap
- Tabs With Dropdown Bootstrap Example
- Right align a Bootstrap dropdown menu
- How to use Bootstrap Dropdown Plugins
- Disable a dropdown item with Bootstrap
- Add headers inside the dropdown menu in Bootstrap
- Toggle class by adding the class name when element is clicked and remove when clicked outside

Advertisements