"Interactive bootstrap tabs nested within a dropdown menu that automatically close upon being clicked

Hey, I've got a dropdown with tabs inside. When I click on certain tabs within it, they close but the content inside the tabs that I click on changes, so it's functioning properly. However, the issue is that it closes when I want it to stay open so that users can click on each tab without it closing. I am using JavaScript to handle opening the dropdown and utilizing

e.stopPropagation(); The tabs with #href are working and not closing, but the content is not changing.

Here's the code:

<nav class="navbar navbar-default">
    <ul class="nav nav-pills">
        <li class="nav-item">
            <a class="nav-link active" href="#">Active</a>
        </li>

        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Dropdown</a>
            <div class="dropdown-menu">
                <ul class="nav nav-tabs animation" role="tablist" >                          
                    <li class="active"><a href="#cars" role="tab" data-toggle="tab">Cars</a></li>
                    <li><a href="#vans" role="tab" data-toggle="tab">Vans & Pickup</a></li>
                    <li><a href="#suv" role="tab" data-toggle="tab">SUVs & Crossover</a></li>
                    <li><a href="#mpv" role="tab" data-toggle="tab">MPVs</a></li>
                    <li><a href="#hybrid" role="tab" data-toggle="tab">Hybrid</a></li>
                    <li><a href="#performance" role="tab" data-toggle="tab">Performance</a></li>
                </ul>

                <!-- Tab panes -->
                <div class="tab-content white-bg-tabs">
                    <div class="tab-pane active" id="cars" role="tabpanel">
                        00. SOME ITEM w IMAGE / LIST HERE 
                    </div>

                    <div class="tab-pane" id="vans" role="tabpanel">
                        0. SOME ITEM w IMAGE / LIST HERE         
                    </div>

                    <div class="tab-pane" id="suv" role="tabpanel">
                         1. SOME ITEM w IMAGE / LIST HERE   
                    </div>

                    <div class="tab-pane" id="suv" role="tabpanel">
                       2. SOME ITEM w IMAGE / LIST HERE     
                    </div>

                    <div class="tab-pane" id="mpv" role="tabpanel">
                         3. SOME ITEM w IMAGE / LIST HERE 
                    </div>

                    <div class="tab-pane" id="hybrid" role="tabpanel">
                         4. SOME ITEM w IMAGE / LIST HERE 
                    </div>

                    <div class="tab-pane" id="performance" role="tabpanel">
                       5. SOME ITEM w IMAGE / LIST HERE 
                    </div>
                </div>
                <!-- container -->  
            </div>
        </li>
    </ul>
</nav>

And here's the JavaScript code. By the way, Bootstrap 4 alpha 6 is being used in this implementation.

$('.dropdown-menu').on('click.bs.dropdown', function (e) {
     e.stopPropagation(); 
   e.preventDefault();
}

Answer №1

i came across the solution here Bootstrap jQuery Tabs are not working in Dropdown

$( document ).ready(function() {
$('.dropdown-menu li').on('click', function(event){
//Preventing event propagation to the document NODE, ensuring delegated events won't fire
   event.stopPropagation();
 });

 $('.dropdown-menu li').on('click', function(event){
   //Preventing event propagation to the document NODE, ensuring delegated events won't fire
   event.stopPropagation();
 });

 $('.dropdown-menu > ul > li > a').on('click', function(event){
  event.stopPropagation();
  $(this).tab('show')
 });
});

credited to user Deep

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

Self-referencing object identifier

Having trouble articulating this question, but I'm attempting to develop a JavaScript object that manages an array of images for reordering and moving purposes. function imgHandler(divname) { this.imgDiv = divname; this.img = Array("bigoldliz ...

Automatically populate select2 dropdown in ASP.NET MVC Core using AJAX

Currently, I am working on a feature to automatically populate text boxes and drop-down fields in my view. To achieve this, I am using a list that I query again. I came across an example that I am referencing here. However, when trying to debug, the break ...

What is the best way to make a dropdown button on a top navigation bar show as active using Semantic-ui?

I searched through the Semantic-ui documentation, but I couldn't find clear instructions on how to designate a dropdown item as 'active' (highlighted without being opened) in my top navbar menu, similar to regular items. The 'active&ap ...

Incorporate the selectpicker feature into a dynamic input field

I am currently utilizing Laravel for my web development. In my controller, I pass a list of questions to the view and display them as follows: @foreach($questions as $q) <div class="col-xs-12"> <input type="{{ $q["type"] }}" class="fo ...

The time parameter in jQuery's ScrollLeft animation method seems to be disregarded

Hey everyone, I'm having trouble understanding this: thumb.animate( {'scrollLeft': active.width()*3}, 'slow' ); The scrolling works fine, but the "slow" parameter seems to be ignored. Instead of moving slowly, it moves instan ...

What is the process for creating a rollover effect with png images and jquery?

I managed to reverse engineer a script that I came across online and it seems to be functioning well. The only issue I'm facing is that the hover image appears with full visibility before any hover action is taken place. Here's the script snippet ...

Navigating through each element of an array individually by using the onClick function in React

I'm currently working on a project that involves creating a button to cycle through different themes when pressed. The goal is for the button to display each theme in sequence and loop back to the beginning after reaching the last one. I've imple ...

Getting the full referrer URL can be achieved by using various methods depending

I am currently working with ASP.Net. My goal is to retrieve the complete referrer URL when visitors arrive at my website from: https://www.google.co.il/webhp?sourceid=chrome-instant&rlz=1C1CHEU_iwIL457IL457&ion=1&espv=2&ie=UTF-8#q=%D7%90 ...

Ensuring uniform column heights with Semantic UI

I came across the "equal height" classes in Semantic UI, but I'm having trouble applying them to inner divs, like the "ui segment" for example. More details can be found here. Take a look at my screenshots below: https://i.sstatic.net/o9kwC.png < ...

Checking React props using Jest and Enzyme - A simple guide

Trying to understand React testing, I came across two files: Button.js and Button.test.js The code below contains the question along with comments: // Button.js import React from 'react'; import { string, bool, func } from 'prop-types&apos ...

Is it possible for HTML/CSS to automatically adjust content size to fit or fill a container?

I'm interested in finding a CSS-only technique that can ensure content within a container scales to fit, regardless of whether it's text or images. Take a look at the example below: .container { display: inline-block; width: 2in; hei ...

What could be causing my CSS background image to not display properly?

For some reason, I can't figure out why it's just displaying a blank screen. This is what I'm seeing: https://i.sstatic.net/0gDIK.png Here is the structure of my files: https://i.sstatic.net/GDToF.png The CSS code looks like this: *{ ...

Guide to dynamically updating the href of an SVG Image in Angular HTML

I am currently iterating through a list of employee objects, each containing an image URL that I need to incorporate into an SVG - Image element. <div *ngFor ="emp of employees"> <defs> <pattern id = "attachedImage" height ...

Parsing CSV files using AngularJS

I am currently developing a CSV file parser using node and Angular. When a user uploads a CSV file, it is processed on the server side with node and the csv-parse library. This results in an array of objects based on the input CSV file. On the Angular si ...

Please enter data into the input fields provided in the text

Below is the code where Google transliteration is used for typing in Indian language in a text field. There are two routes with different page IDs. Initially, the transliteration works fine on the default page. However, when changing routes, an error occur ...

What is the process for customizing the arrow of a <select> dropdown menu exclusively?

Here is the code for a dropdown menu: <select id="dropdown"> <option value="">Go to page...</option> <option value="http://stackoverflow.com">CSS-Tricks</option> <option valu ...

Issues with styling classes using global SCSS in React are causing unexpected behavior

Currently, I am working on a React project that includes the use of SASS for styling purposes. While implementing modular CSS in my components, I have encountered an issue with applying styles from a main.scss file in my Layout.js component. The unique a ...

The subscription data for nested classes appears to be displaying as undefined

In my current project, I am utilizing Angular 8 and facing an issue with a nested class. The problem arises when trying to access data from an observable subscribe operation in the child class (Players) within the main Tournament class. Until the data is r ...

How can I make all fields in the CKAN Resource form html the same size as the "Description" field?

I am completely new to CKAN and front-end development. I've been scouring through various html/css files without success in locating where I can adjust the field sizes in the resources form (where users can modify metadata via GUI). I would like to r ...

What are the steps to assign a personalized title to the PDF file being saved with the FPDF toolkit?

If you're familiar with the solution, just refer to the end where it says Question, so you can skip the explanation and save time. Currently, I am utilizing the FPDF library which typically opens PDFs directly in the browser by default. To change th ...