Prevent Dropdown menu from closing if I click a menu item

50
January 13, 2021, at 02:10 AM

I have a drop down menu in sidebar and it has links as menu items. When I click a menu item(link) then link works fine but drop down menu gets closed.

But I want that dropdown menu stay opened even after clicking a menu item.

HTML Code:

<div id="sidebar-wrapper">
     <div class="sidebar-heading">Start Bootstrap </div>
     <div class="list-group list-group-flush">              
          <a href="{% url 'shop:admin_orders_list' %}">All orders</a>
          <button class="dropdown-btn button">Products
               <i class="fa fa-caret-down"></i>
          </button>
          <div class="dropdown-container">
               <a href="{% url 'shop:admin_products_list' %}">View Products</a>
               <a href="{% url 'shop:admin_product_create' %}">Add New Product</a>
          </div>   
     </div>
</div>

I tried these two following ways:

$('div.dropdown-container a').on('click', function(e) {
        e.preventDefault();
});
$('div.dropdown-container a').on('click', function(e) {
        e.stopPropagation();
});

But these two ways did not work.

Please help me to resolve it.

Answer 1

try this make sure to put your dropdown id there

$('#dropdownid').on('hide.bs.dropdown', function () {
    return false;
});
READ ALSO
{select: false} works differently on mongoose queries

{select: false} works differently on mongoose queries

I am trying to create a user in mongoose and return it after Usercreate query without password field

56
How to generate random password in python [duplicate]

How to generate random password in python [duplicate]

I want to use python3 to generate random password to encrypt my files, The random password created should have following restriction

75
Post Image data in android studio to a server url not working on android 4.1.2

Post Image data in android studio to a server url not working on android 4.1.2

I am taking a screenshot on my android app using this code:

75
Android studio Build failed with NDK

Android studio Build failed with NDK

found error while build the project with NDK

79