Issue with Bootstrap/Bootswatch Dropdown Tab Not Showing Up

I am encountering an issue while trying to implement a tab with a dropdown navigation, similar to the examples shown on Bootswatch. Interestingly, it seems that this functionality is not working properly even on the demo page provided by Bootswatch.

My main objective here is to have one of the tabs contain a dropdown menu that changes the content displayed in the tab body based on the selection made. While the other tabs are functioning as expected, the dropdown menu fails to show the intended contents.

Below you will find a simplified version of the code from the Bootswatch page example:

<!doctype html>
<html lang="en" class="h-100">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Title</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootswatch/4.4.1/cerulean/bootstrap.min.css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css">
</head>

<body class="d-flex flex-column h-100">

    <header>
        <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
            <a class="navbar-brand" href="/">Title</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01"
                aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarColor01">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="#">Home</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="#">Settings <span class="sr-only">(current)</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Help</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">About</span></a>
                    </li>
                </ul>
            </div>
        </nav>
    </header>

    <main role="main" class="flex-shrink-0">
        <div class="container" id="settingsapp">

            <div class="page-header" id="banner">
                <h1>Settings</h1>
            </div>
            <ul class="nav nav-tabs">
                <li class="nav-item">
                    <a class="nav-link active" data-toggle="tab" href="#home">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" data-toggle="tab" href="#profile">Profile</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" style="">
                        <a class="dropdown-item" data-toggle="tab" href="#dropdown1">Action</a>
                        <a class="dropdown-item" data-toggle="tab" href="#dropdown2">Another action</a>
                    </div>
                </li>
            </ul>
            <div id="myTabContent" class="tab-content">
                <div class="tab-pane fade show active" id="home">
                    <p>Home tab content.</p>
                </div>
                <div class="tab-pane fade" id="profile">
                    <p>Profile tab content.</p>
                </div>
                <div class="tab-pane fade" id="dropdown1">
                    <p>Dropdown 1 content.</p>
                </div>
                <div class="tab-pane fade" id="dropdown2">
                    <p>Dropdown 2 content.</p>
                </div>
            </div>
        </div>
    </main>

    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

</body>

</html>

As someone relatively new to Bootstrap and Bootswatch, my approach typically involves finding existing solutions and then customizing them to suit my needs. This particular endeavor has proven to be a bit challenging for me, but I view it as an opportunity to learn and improve my skills in this area.

Answer №1

If you're using Bootstrap, typically you'll need the Jquery.js and bootstrap.js <script> tags to handle user interactions. Make sure you have included them in your code.

<head>
<meta charset="utf-8>
<:title>Bootswatch: Cerulean</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="../4/cerulean/bootstrap.css" media="screen">
<link rel="stylesheet" href="../_assets/css/custom.min.css">

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" ></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" ></script>

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" ></script>

Answer №2

Thanks to a helpful collaborator, I was able to solve this issue. It turns out that I was missing the "data-toggle" argument within the dropdown-menu div:

<div class="dropdown-menu" style="">
    <a class="dropdown-item" href="#dropdown1">Action</a>
    <a class="dropdown-item" href="#dropdown2">Another action</a>
</div>

This code should be updated to include the "data-toggle" attribute:

<div class="dropdown-menu" style="">
    <a class="dropdown-item" data-toggle="tab" href="#dropdown1">Action</a>
    <a class="dropdown-item" data-toggle="tab" href="#dropdown2">Another action</a>
</div>

Next step is figuring out how to submit a PR on Bootswatch since this issue was based on their examples.

I have made the necessary corrections in the above question by adding the missing HTML attributes.

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

What is the best way to manage variables when iterating over an object of objects in a loop that contains inner asynchronous code?

I am working on a Node/Express server with a GET route where I need to send back a response to the client. The response consists of an array of objects, each with a 'url' property that contains a base64 encoded image retrieved using the 'bas ...

"Extracting regular expressions between the penultimate and ultimate characters

I'm struggling with a simple regex question. I want to extract text between two specific characters: - and ~ Here's my string: Champions tour - To Win1 - To Win2 ~JIM FURYK Currently, when I use this regex pattern: \-([^)]+\~), it mat ...

Troubles with IE7 regarding jQuery [clicking and changing events]

My code snippets are designed to loop through cached JSON data on the 1st click function and display any values that exist for a specific id. The 2nd change function captures when elements' values change (e.g., from yes to no). Since these elements a ...

What is the process for uploading a file and storing it in a specific directory?

Creating HTML Form for File Upload: <div style="width:200px"> <form action="javascript:_bulkUser();" method="post" enctype="multipart/form-data"> Select File:<input type="file" name="fname"/><br/> <input type="submit ...

javascript: revealing the identity of a click event handler

Here I am looking to create a click function with a specific name and parameters for the purpose of code reusability. This will allow me to write one generic function that can be used for common tasks like enabling users to delete various types of data. I ...

Each Jest test file should have a specified window.location

After upgrading to Jest 22, I encountered an issue with mocking window.location. Previously, this method worked fine but stopped working after the update. Object.defineProperty(window.location, 'href', { writable: true, value: 'http ...

Ways to access a DOM element in Next.js when the class name is dynamically generated

I am currently developing a Next.js app (version 12.1.0) and facing an issue in my Nav component. I am attempting to select a DOM element using const nav = document.querySelector('.nav'); However, this is triggering an error message: TypeError: ...

Activate an asynchronous request within a dropdown menu that was loaded using ajax

Let me start by presenting a simplified version of my code: HTML : <form id="add"> <select id="cat"> <option selected value="">…</option> <option value="a">A</option> <option value="b"& ...

What could be causing Next.js to throw an error upon completion of the MSAL OAuth process?

I encountered an error while building a website using next.js. The site is set up for production, and after the authentication process with MSAL for Azure AD integration, I am facing the below error during the OAuth loop. As a beginner in next.js coming fr ...

Storing Nested Array-Objects in MongoDB: Best Practices

I am facing challenges with storing data in MongoDB Atlas. The array I am trying to store looks like this: Array [ Array [ "6352546fb6e1702a96df5931", "[{\"date\":\"2022-10-21\"},{\" ...

What is the purpose of having the same function for onPress in React Native components?

As a beginner in learning react-native, I like to search random projects on GitHub and analyze what seems weird or hard to understand. Today, I came across some code from an unknown individual that looked like this: {isTrue && ( <Touch ...

What is the best way to merge the value of an input field (contained in an array) with another input field before submitting the form

Currently, I am in the process of editing the data in a form's input field. I know that submitting form data this way is not ideal, but I encountered a challenge with getting the value from a datetimepicker into the ng-model. Specifically, I was able ...

Open the application through the web browser; if it can't be found, direct to the app store

Looking for a solution for my application that uses a webview to make references to other applications. Here's what I need: -If the referenced application is installed, it should launch it -If the referenced application is not installed, it should p ...

Opt for a line break over a semicolon when using jQuery

I need assistance with breaking the line wherever a semicolon is present. var locdata = { "locations": [{ "id": 0, "name": 'USA', "cx": 100, "cy": 100, "address":'545, 8t ...

Issue with the height of content in Mobile Safari when using Bootstrap 4 columns

I have incorporated Bootstrap 4 into my website's design, specifically utilizing the bootstrap grid layout in flex mode. Within one of the columns, I have placed a button that I desire to fill the entire column width. I have achieved this by setting ...

Animating the smooth collapse of panels within listviews

I have successfully implemented a smooth animation code for a collapsible panel, and it is working wonderfully: <script type="text/javascript"> function pageLoad(sender, args) { smoothAnimation(); } function smoothAnimation() ...

Tips for creating a unique parent tag and child tag with onclick functionality on a b-form-checkbox without repeating code

As I work on a li tag with various child elements, including a b-form-checkbox, I encountered an issue. I want the checkbox to function properly when clicked anywhere inside the li tag, including on the checkbox itself. However, when I click directly on th ...

The functionality of Access-Control-Allow-Origin is not effective in Chrome, yet it operates successfully in Firefox

I'm facing an issue with my code in the HTML file. I have a second file that I want to load content from, and both files are located in the same directory <div id="mainMenu"></div> <script> $(function() { $('#mainMe ...

Enhancing user experience with jquery autocomplete matching

Currently utilizing the JQuery Autocomplete plugin. It seems that the default behavior is to match from the start, so "foo" matches "fool", but not "bufoon". I am seeking a way for matching to happen anywhere in the text and also in a case-insensitive man ...

What causes the absence of data in req.body after submitting a form in quiz.ejs?

app.js const express = require('express'); const mongoose = require('mongoose'); const path=require('path'); const app = express(); // Establish MongoDB connection async function initDatabase(){ await mongoose.connect(&ap ...