This is getting annoying — when I click on an item in a Bootstrap dropdown, the dropdown doesn't close. I have it set up to open a Facebox lightbox when you click the dropdown item but there is a problem with it.
When the item is clicked, I tried doing this:
$('.dropdown.open').removeClass('open'); $('.dropdown-menu').hide();
That hides it, but then for some reason it won't open again.
As you can see I really need the dropdown to close, because it looks crappy when it stays open (mainly because the z-index
of the dropdown is higher than the Facebox modal box overlay.
If you're wondering why I'm not using the nice-looking modal box built into Bootstrap, it is because:
$.facebox({ajax:'/assets/ajax/dialogs/dialog?type=block-user&id=1234567'});
Usage. Via data attributes or JavaScript, the dropdown plugin toggles hidden content (dropdown menus) by toggling the . show class on the parent list item.
Every Bootstrap dropdown button or link has an ::after selector in CSS. ::after selector is often used to insert some text after the content of the element. In this case, the content is a dropdown arrow. To remove it, just make the content go 'none'.
In Bootstrap 4, you can remove the dropdown arrow which is called caret by declaring a $enable-caret SASS variable and setting it to false : $enable-caret: false; This overrides the default value of true set in the Bootstrap's _variable.
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() .
Try this:
$('.dropdown.open .dropdown-toggle').dropdown('toggle');
This may also work for you:
$('[data-toggle="dropdown"]').parent().removeClass('open');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With