Keep Dropdown menu open when clicking on a menu item to avoid closing

I'm facing an issue with a drop-down menu in the sidebar that contains links as menu items. Whenever I click on a menu item (link), the link works fine but the drop-down menu closes.

What I actually want is for the drop-down menu to stay open even after clicking on a menu item.

Here's a snippet of the 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've tried a couple of ways to address this issue:

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

Unfortunately, neither of these approaches have worked so far. Any suggestions on how to resolve this would be greatly appreciated.

Answer №1

Give this a go and remember to insert the ID of your dropdown menu

$('#dropdownid').on('hide.bs.dropdown', function () {
    return false;
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unusual Vue syntax: deconstructing `state` from `this.$store` with a default value of an

While working on a pre-existing project, I came across some interesting notation in a Vue project utilizing Vuex: const { state = {} } = this.$store; const { orders = {} } = state; This code snippet appears to be creating a local object named "state" tha ...

How does Django approach namespacing ModelAdmin.get_urls with model(admin) inheritance?

TL;DR Is it possible to define well-named views with namespaces when extending ModelAdmins using ModelAdmin.get_urls without relying on ModelAdmin.model._meta or similar solutions? Pretext Views added through get_urls are being overridden when custom Mo ...

Eliminate every instance using the global regular expression and the replace method from the String prototype

function filterWords(match, before, after) { return before && after ? ' ' : '' } var regex = /(^|\s)(?:y|x)(\s|$)/g var sentence1 = ('x 1 y 2 x 3 y').replace(regex, filterWords) console.log(sentence1) sentence2 ...

I am experiencing difficulties getting my three.js application to run smoothly on mobile devices

My iPhone running on iOS 13.7 has been able to flawlessly run all the three.js examples, including fat lines and orbit controls. However, when I try to run my own code on mobile, it doesn't seem to work. You can check out the source code and the uplo ...

How can I create a more spacious and stylish JTextField for my address bar?

I am working on developing my Java skills by creating a custom browser. Is there a way to adjust the size and shape of the address bar, which is currently implemented as a JTextField with Swing's default settings? Here is the code snippet I am using: ...

Efficiently submitting multiple forms in a single click

On my photo portfolio admin page, I have created a feature to caption, keyword, and credit each photo. Previously, I had multiple forms listed dynamically with submit buttons for each form. With over 20 photos/forms on the page, this process became tedious ...

Reposition icons accordingly while incorporating a new set of icons

After creating a new icon set font, I noticed that the icons are not positioning correctly and appear smaller than expected when loaded: https://i.stack.imgur.com/1OsAL.png https://i.stack.imgur.com/zmLQq.png I attempted to adjust the .icon class by add ...

Angular routing does not properly update to the child's path

I've organized my project's file structure as follows: app/ (contains all automatically built files) app-routing.module.ts components/ layout/ top/ side/ banner/ pages/ ...

How can I trigger my function in jQuery after inputting into the jQuery text field?

Looking for advice on implementing a function in jQuery for a text field that is not working as expected. The code works fine when creating a text field in HTML, but encounters issues with the jQuery text field. <!DOCTYPE html> <html> <body ...

I am in need of setting up two rows side by side using the display

I'm trying to have two rows side by side using display grid, but I'm facing some issues. When I use the following CSS... .grid-container { display: grid; grid-template-rows: auto auto; grid-template-columns: auto; grid-column-gap: 100px;} It cre ...

Collecting information from form submissions, accessing data from the database, and displaying the results

I am currently working on a project using nodejs, express, and mongodb within the cloud9 IDE. My goal is to create a page with a form that allows users to input data, search for corresponding information in the database, and display that data on the same ...

Update the fuelux treeview after uploading a file

Currently, I am utilizing the jquery fileupload plugin to facilitate the process of uploading a file and then using the data from said file to populate a fuelux treeview. I have configured an ajax call for handling the file data where the information is fe ...

Header and footer set in place with customizable height paired with a dual-module sidebar

I'm working on a layout that includes a fixed footer and header. My goal is to make the height of the "info-box" div variable, while having the "scrolling-div" fill the remaining vertical space in the right column. The issue arises when setting the he ...

When used, the jQuery selector returns the PreviousObject rather than the object that was selected initially

I'm currently attempting to add a second menu to my website alongside the top menu. I have multiple menus set up in two bootstrap columns (col-8 and col-4). Initially, when I used jQuery selectors outside of a function, everything worked smoothly. How ...

The functions Show() and Hide() may not work in all scenarios within jQuery

I'm currently developing a website that allows users to participate in quizzes. Each quiz consists of 20 questions divided into three sections: 1 mark for 10 questions, 2 marks for 5 questions, and 4 marks for 5 questions. For each question, there are ...

Iterating over each element within an array using the map method

I am facing an issue while trying to map values to a new array. The challenge lies in the fact that the property I am mapping can either be a number or an array. When it comes to arrays, I encounter a problem as my result ends up being an associative arra ...

How to delete the last element of an array in Vue.js

Currently, I'm facing an issue with a filter duplication feature in my code. When I click on the "add filter" button, a duplicated filter is added to the array. However, the problem arises when I try to remove a filter using the cross icon - it always ...

How to dynamically change the placeholder in an Angular 2 Material Input field

Is it possible to dynamically change the text of an input placeholder? I am able to update the text using console.log, but the interface does not reflect the change. How can I make the interface recognize the updated placeholder text? document.getElemen ...

Having trouble with Discord.js version 12 and the messageReactionAdd event not triggering properly?

client.on('messageReactionAdd', (reaction, user) => { console.log('If you see this I actually work...'); }); I am having some trouble with my code. Despite setting up a simple console log, it seems like the code is not running prope ...

When resetting a form, the styled radio buttons remain selected and do not deselect

I have a set of three styled radio buttons for car rental pickup locations: <div class="col-md-12 form-group"> <label for="car-rental-pickup-location" class="mb-2">Pickup Location<small class="text-danger">*</small></label>&l ...