What could be causing the collapsible links in my Bootstrap 5 project to be unresponsive?

I encountered an issue when updating from Bootstrap 4.5.3 to version 5.0.0 using the CDN bundle. Previously, with Bootstrap 4.5.3 loaded via the CDN bundle, a dropdown feature was working perfectly:

<!-- Nav Item - Pages Collapse Menu -->
<li class="nav-item">
    <a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseTwo"
        aria-expanded="true" aria-controls="collapseTwo">
        <span>AAAA</span>
    </a>
    <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionSidebar">
        <div class="bg-white py-2 collapse-inner rounded">
            <h6 class="collapse-header">BBBB</h6>
            <a class="collapse-item" href="CCCC.html">CCCC</a>
            <a class="collapse-item" href="DDDD.html">DDDD</a>
        </div>
    </div>
</li>

However, after upgrading to Bootstrap 5.0.0 through the CDN bundle:

<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dcbeb3b3a8afa8aebdac9ce9f2ecf2ecf1beb9a8bded">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>

The dropdown feature became unresponsive. I'm puzzled about why this change led to the malfunctioning of the dropdown. Any insights or tools for troubleshooting would be greatly appreciated.

For reference, my project originally used Bootstrap 4.5.3 as shown by this line in index.html:

<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

The transition to Bootstrap 4.5.3 via the CDN bundle was seamless and everything continued to function properly. However, changing that last script line to upgrade to Bootstrap 5.0.0 introduced issues within the dropdown functionality.

If anyone can shed light on how to successfully migrate this code to Bootstrap 5.0.0 and whether JQuery is necessary for the process, it would be of immense help.

Answer №1

While Bootstrap 5 does not necessarily require jQuery, it is still compatible with it.

Upon examining your code against the Collapse documentation, you will notice that there has been a change in attribute naming from data-toggle to data-bs-toggle for Bootstrap 5. Additionally, anchors now utilize the href attribute to specify the target, as opposed to a data attribute. Resolving these issues should address any functionality concerns.

<!DOCTYPE html>

<head>
  <!-- Include Bootstrap CSS (Version 5.0.0) via CDN-->
  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e3c31312a2d2a2c3f2e1e6b706e706e733c3b2a3f6f">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">

</head>

<body>
  <ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" 
    id="accordionSidebar">

    <!-- Navbar Item - Expandable Menu -->
    <li class="nav-item">
      <a class="nav-link collapsed" href="#collapseTwo" 
      data-bs-toggle="collapse" aria-expanded="true" aria-controls="collapseTwo">
        <span>Components</span>
      </a>

      <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" 
      data-parent="#accordionSidebar">
        <div class="bg-white py-2 collapse-inner rounded">
          <h6 class="collapse-header">Custom Components:</h6>
          <a class="collapse-item" href="buttons.html">Buttons</a>
          <a class="collapse-item" href="cards.html">Cards</a>
        </div>
      </div>
    </li>
  </ul>
  <!-- End of Sidebar -->

  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="492b26262d3a3d3b2839097c67796779642b2c3d2878">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
</body>

</html>

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

Stretching a row in Wordpress Visual Composer and setting the direction to Right-to-Left

Whenever I attempt to expand a row using the row settings in Visual Composer, the row stretches but the alignment of the row becomes completely off. This issue only occurs when the body direction is set to direction:rtl in the CSS. You can view the websit ...

Obtaining the URL of a page when a link is clicked in an email

Is there a way to automatically append the URL of the page when a link in an email is clicked? I attempted using javascript and Iframes, but it seems that email clients disable these features for security reasons. I also experimented with Mailgun webhooks, ...

abandoning the upload of an item into a THREE.js environment

Currently, I am working on a THREE.js scene where I need to prevent uploading multiple files into the scene simultaneously. The setup involves using Angular to implement the three js scene and canvas as a factory to maintain only one instance of a canvas a ...

Conversation taking place outside of an iframe

Having a slight issue with a JavaScript dialog. There's a button and a dialog inside an iframe with the following code: $( "#correcto" ).dialog({ width: 600, closeOnEscape: true, autoOpen: false, draggable: false, modal: true, ...

Stop Magnificent Popup Iframe when Clicking on a Link

I am currently using a Magnific Popup iframe to display a form (created with Machforms). <div align="center"> <a class="popup-link" href="...machform/view.php?id=3717"> <img src="images/image.png"> </a> </div> Once ...

Error: The script is unable to access the property "div" because it is undefined

I keep encountering this issue "Cannot read property 'div' of undefined" This is the snippet in question function validateData(){ for(let j = 0; j < 13; j++){ if(dataArr[j].data.textContent === resultSet[j].result.div. ...

retrieve only the following occurrence throughout the entire file

I am looking to target only the first occurrence of an element in the document after a clicked element. Here is my current approach: $('.class').click(function(){ var x = $(this).nextAll('.anotherclass').first(); //do something ...

Is there a way to eliminate the additional space on the right side of this bootstrap 4 modal?

Take a look at this fiddle: https://jsfiddle.net/apo5u0mt/ Below is the code snippet: HTML <div class="modal" id="galleryModal"> <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-xl"> <div class="modal-con ...

Can you provide guidance on how to divide a series of dates and times into an array based

Given a startDate and an endDate, I am looking to split them into an array of time slots indicated by the duration provided. This is not a numerical pagination, but rather dividing a time range. In my TypeScript code: startDate: Date; endDate: Date; time ...

What are the steps for implementing this javascript code in an HTML document?

Recently, I've been seeking advice on how to address the issue of wanting a button click to automatically select the search box on my website. Suggestions have pointed towards using Javascript for this functionality, with the following code recommend ...

The issue of integrating jQuery with the textarea CKEditor is still unresolved

I'm having an issue with applying the ckeditor function to append data in my code. I have included a cdn link for ckeditor in the header.php file, but it's not working as expected. How can I resolve this? <script> $(document).ready(func ...

The JQuery .ajax() function is not functioning properly, although the success method is still executing

Having issues with an ajax call on a webpage. The WebMethod is working fine. Potential problem - ajax method called from UserControl embedded in a content page within a master page, accessible only after .Net authentication. Including this info for transp ...

I am experiencing an issue where my observable value gets reset after setting it in KnockoutJS + Chosen

Currently, I am in the process of creating a user interface for building charts. Users have the ability to select fields from a database in order to construct a graph. Additionally, these graphs come with a refresh interval dropdown feature. Everything fu ...

Utilizing ES6 modules in an Adobe XD extension: A comprehensive guide

Is it possible to utilize ES6 imports within XD plugins? When attempting to use import Vue from 'vue', the build task is successful, but XD throws an error in the developer console during plugin loading: Plugin Error: Error loading plugin <s ...

Firefox detects video interference from webcam

Take a look at this test code: <!doctype html> <html> <body> <video id="v1" autoplay="autoplay"></video> <script> navigator._getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserM ...

The ajax Success function fails to work when set to receive JSON data

My task involves adding an attendance record for a group of students within a classroom using a Bootstrap modal. Below is the code snippet for my Bootstrap modal, containing a form: <div id = "add_attendance_modal" class = "modal fade&qu ...

Arranging object arrays according to strings

Imagine there is an array: var a = [ { name: 'Tom', surname: 'TestAsIvanov' }, { name: 'Kate', surname: 'Ivanova' }, { name: 'John', surname: 'Alivanov' }, { name: 'Ivan&apos ...

Using Meteor JS to save images in MongoDB

Looking to save an image uploaded via a file input into a database. Utilizing the redactor plugin to browse the image with the following code: $('.editor').redactor({ imageUpload:"/uploads" }); Once an image is selected or browsed, it is se ...

What is the best way to conceal elements that do not have any subsequent elements with a specific class?

Here is the HTML code I have, and I am looking to use jQuery to hide all lsHeader elements that do not have any subsequent elements with the class 'contact'. <div id="B" class="lsHeader">B</div> <div id="contact_1" class="contac ...

What is the process for loading a font file in Vue.js and webpack?

I've done a lot of research, but I couldn't find any links that show me exactly how to add fonts in VueJS. This is the method I'm using to import the font in my LESS file: @font-face { font-family: "Questrial"; src: url("../../fonts/Que ...