What is causing the Bootstrap accordion to not display content when clicked on?

As a beginner in web development, I am currently working on my very first website. One issue I'm facing is with incorporating an accordion-style card in my webpage. Although it allows me to click on different titles, the collapsed ones fail to expand and show the descriptions inside. Any suggestions on what mistake I might be making and how to rectify it?

https://i.stack.imgur.com/FXwq0.png

<div class="col col-sm order-sm-first col-md">
        <div class="col">
            <h2>Corporate Leadership</h2>

            <div class="accordian">
                <div class="card">
                    <div class="card-header" role="tab" id="peterhead">
                        <h3 class="mb-0">
                            <a data-toggle="collapse" data-target="#peter">
                                Peter Pan <small>Chief Epicurious Officer</small>
                            </a>
                        </h3>
                    </div>
                    <div class="collapse show" id="peter" data-parent="#accordion">
                        <div class="card-body">
                            <p class="d-none d-sm-block">Our CEO, Peter, credits his hardworking East Asian immigrant parents who undertook the arduous journey
                                to the shores of America with the intention of giving their children the best future. His mother's
                                wizardy in the kitchen whipping up the tastiest dishes with whatever is available inexpensively at
                                the supermarket, was his first inspiration to create the fusion cuisines for which
                                <em>The Frying Pan</em> became well known. He brings his zeal for fusion cuisines to this restaurant,
                                pioneering cross-cultural culinary connections.</p>
                        </div>
                    </div>
                </div>
                <div class="card">
                    <div class="card-header" role="tab" id="dannyhead">
                        <h3 class="mb-0">
                            <a class="collapsed" data-toggle="collapse" data-target="#danny">
                                Dhanasekaran Witherspoon <small>Chief Food Officer</small>
                            </a>
                        </h3>
                    </div>
                    <div class="collapse" id="danny" data-parent="#accordion">
                        <div class="card-body">
                            <p class="d-none d-sm-block">Our CFO, Danny, as he is affectionately referred to by his colleagues, comes from a long established
                                family tradition in farming and produce. His experiences growing up on a farm in the Australian outback
                                gave him great appreciation for varieties of food sources. As he puts it in his own words,
                                <em>Everything that runs, wins, and everything that stays, pays!</em></p>
                        </div>
                    </div>
                </div>
                <div class="card">
                    <div class="card-header" role="tab" id="agumbehead">
                        <h3 class="mb-0">
                            <a class="collapsed" data-toggle="collapse" data-target="#agumbe">
                                Agumbe Tang <small>Chief Taste Officer</small>
                            </a>
                        </h3>
                    </div>
                    <div class="collapse" id="agumbe" data-parent="#accordion">
                        <div class="card-body">
                            <p class="d-none d-sm-block">Blessed with the most discerning gustatory sense, Agumbe, our CTO, personally ensures that every dish
                                that we serve meets his exacting tastes. Our chefs dread the tongue lashing that ensues if their
                                dish does not meet his exacting standards. He lives by his motto,
                                <em>You click only if you survive my lick.</p>
                        </div>
                    </div>
                </div>
                <div class="card">
                    <div class="card-header" role="tab" id="albertohead">
                        <h3 class="mb-0">
                            <a class="collapsed" data-toggle="collapse" data-target="#alberto">
                                Alberto Somayya <small>Executive Chef</small>
                            </a>
                        </h3>
                    </div>
                    <div class="collapse" id="alberto" data-parent="#accordion">
                        <div class="card-body">
                            <p class="d-none d-sm-block">Award-winning three-star Michelin chef with wide International experience having worked closely with
                                whos-who in the culinary world, he specializes in creating mouthwatering Indo-Italian fusion experiences.
                                He says, <em>Put together the cuisines from the two craziest cultures, and you get a winning hit! Amma Mia!</em></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

Answer №1

There was a confusion in your classes, as they were not properly aligned with the headers and content they were supposed to represent.

Please review the following code:

<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.0/js/bootstrap.min.js"></script>

<div class="container">
  <h2>Corporate Leadership</h2>
  <div id="accordion">
    <div class="card">
      <div class="card-header">
        <a class="btn" data-bs-toggle="collapse" href="#peter">
          <h3>Peter Pan <small>Chief Epicurious Officer</small></h3>
        </a>
      </div>
      <div id="peter" class="collapse show" data-bs-parent="#accordion">
        <div class="card-body">
          Our CEO, Peter, credits his hardworking East Asian immigrant parents who undertook the arduous journey to the shores of America with the intention of giving their children the best future. His mother's wizardy in the kitchen whipping up the tastiest dishes
          with whatever is available inexpensively at the supermarket, was his first inspiration to create the fusion cuisines for which The Frying Pan became well known. He brings his zeal for fusion cuisines to this restaurant, pioneering cross-cultural
          culinary connections.
        </div>
      </div>
    </div>
    <div class="card">
      <div class="card-header">
        <a class="collapsed btn" data-bs-toggle="collapse" href="#danny">
          <h3>Dhanasekaran Witherspoon <small>Chief Food Officer</small></h3>
        </a>
      </div>
      <div id="danny" class="collapse" data-bs-parent="#accordion">
        <div class="card-body">
          <p class="d-none d-sm-block">Our CFO, Danny, as he is affectionately referred to by his colleagues, comes from a long established family tradition in farming and produce. His experiences growing up on a farm in the Australian outback gave him great appreciation for varieties
            of food sources. As he puts it in his own words, <em>Everything that runs, wins, and everything that stays, pays!</em>
          </p>
        </div>
      </div>
    </div>
    <div class="card">
      <div class="card-header">
        <a class="collapsed btn" data-bs-toggle="collapse" href="#agumbe">
          <h3>Agumbe Tang <small>Chief Taste Officer</small></h3>
        </a>
      </div>
      <div id="agumbe" class="collapse" data-bs-parent="#accordion">
        <div class="card-body">
          <p class="d-none d-sm-block">Blessed with the most discerning gustatory sense, Agumbe, our CTO, personally ensures that every dish that we serve meets his exacting tastes. Our chefs dread the tongue lashing that ensues if their dish does not meet his exacting standards.
            He lives by his motto, <em>You click only if you survive my lick.</em>
          </p>
        </div>
      </div>
    </div>
    <div class="card">
      <div class="card-header">
        <a class="collapsed btn" data-bs-toggle="collapse" href="#alberto">
          <h3>Alberto Somayya <small>Executive Chef</small></h3>
        </a>
      </div>
      <div id="alberto" class="collapse" data-bs-parent="#accordion">
        <div class="card-body">
          <p class="d-none d-sm-block">Award winning three-star Michelin chef with wide International experience having worked closely with whos-who in the culinary world, he specializes in creating mouthwatering Indo-Italian fusion experiences. He says, <em>Put together the cuisines from the two craziest cultures, and you get a winning hit! Amma Mia!</em>
          </p>
        </div>
      </div>
    </div>
  </div>
</div>

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 could be preventing my HTML replacement assignment from functioning properly?

Whenever a choice is made, I want to substitute the current content with different content. My current attempt is to update the content from "HuckFinn" to "Tom Sawyer will be added later" when the user selects "Tom Sawyer" from the drop-down menu. However, ...

The dataTable plugin is malfunctioning, displaying all records on a single page when it should only show 10 per page

I utilized the dataTable plugin to format my HTML table, but unfortunately it is not displaying the results as expected. Instead of showing 10 records per page, it is displaying all records at once. I even tried setting "iDisplayLength: 10" but it didn&apo ...

Avoiding the use of mailto links in PHP

One problem I encountered is with a mailto link in my PHP code: <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f5a525e56537f5b50525e5651114b535b">[email protected]</a>?subject=<?php rawurlencode ...

What is the best way to ensure my arrow text remains properly positioned when using fullpage.js?

Seeking guidance from the web development community. I am currently working on a client's website that utilizes fullpage.js and encountering a persistent issue. On slide1 of the website, I am struggling to display the correct text next to the arrows. ...

Is there a potential bug in Chrome with the submit button appearing "depressed" when focused?

Why do submit buttons act differently in Chrome? <input type='text' placeholder='Dummy Input'/> <input type='submit'/> In Chrome, the active 'depressed' state of the submit button will only occur if the ...

Setting a specific time for a div element with opacity: A step-by-step guide

Is there a way to adjust the timing for the appearance of the add-to-cart when hovering over the product-list-item? Currently, it appears when I hover over the item and disappears when I move my mouse away. .product-list-item { position: relative; w ...

Utilize jQuery to swiftly align elements within a designated container

Check out my JSFiddle example: http://jsfiddle.net/c62rsff3/ I'm attempting to implement snapping behavior between 2 elements using this code: $('.draggable-elements').draggable({ snap: true }); In addition, I've defined a container ...

Unleashing the Power of the "OR" Operator in Form Field Validation

The custom JavaScript function FormQuote_Validator is used to validate form fields. It should return the value "TRUE" and display an alert message if all three input fields are submitted without any numbers; otherwise, it should return the value "FALSE". ...

Is the "data-export-data-type="all" parameter not functioning properly for exporting data from all pages within the bootstrap table plugin?

I'm currently utilizing the bootstrap table extended in conjunction with bootstrap 4. My goal is to utilize the export button to download data from all pages. The CSS file being used is: <link rel="stylesheet" href="https://unpkg.co ...

What could be the reason behind ng-bind-html only displaying text and not the link?

Utilizing ng-repeat to exhibit a list on my webpage. One of the fields in my data contains a URL that I want to display as an actual link within my HTML page. Please refer to the screenshots below: My HTML: My rendered page: I have included the angular- ...

How to display umlauts (åäö) using Verdana font in Internet Explorer versions 8 and 9

Encountering a strange issue on certain pages where the rendering of umlauts (åäö) appears incorrect in IE8 and IE9 at times. The encoding is utf-8 (and most of the site functions correctly, so I know it's correct). I have attempted to isolate the ...

What could be causing the month to be undefined in this Javascript date?

var currentDate = new Date(); var currentMonth = currentDate.getMonth(); var monthArray = [ 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'S ...

The row in the table is not reaching its maximum height

Trying to design a layout with a topbar followed by a split layout has posed some challenges. The main issue I encountered was the need for the width and height to adjust automatically based on the browser size. To address this, I attempted to use a table ...

What is the best way to replace a CSS Background that is already marked as important?

Attempting to change the background of a website using Stylish, but encountering issues. The existing background css on the website includes an !important rule which is preventing Stylish from taking effect. Here is my code: body { background-image: n ...

"The Zorro table is filled with items of various types, although unfortunately, the Intellisense is not as accurate as it

Imagine a scenario where you have a basic table set up: <nz-table #table [nzData]="users"> <thead> <tr> <th>Id</th> <th>First Name</th> <th>Last Name</th> </tr> ...

I'm not entirely sure why I keep getting the error message stating "Cannot read property 'innerHTML' of null"

Having an issue with my JavaScript code where I am trying to insert a new table row into the HTML but keep getting an error message that says "Uncaught TypeError: Cannot read property 'innerHTML' of null" <!DOCTYPE html> <html lang=" ...

Do not use Express.js to serve the index.html file

Encountered an issue when attempting to run my Express.js solution. Instead of opening my desired index.html file located in the client directory, it kept opening the index.jade file from the views folder with the message "Welcome to Express" on the browse ...

Interested in extracting an HTML table from a Form element within a Python Flask application?

So, in my Flask application, I need to retrieve all the content within a table element. <form action="#"> <table > <tr> <th><input type="text" id="txtName"/></th> ...

Arranging HTML elements with jQuery - the existing script flips back and forth

I have created a code snippet on CodePen that showcases a feature of the website I am currently developing: http://codepen.io/barrychapman/pen/BzJGbg?editors=1010 Upon loading the page, you will notice 6 boxes. The first box is active, while the remaining ...

Is your max-height transition not functioning properly?

Is there a way to create a collapsible panel using only CSS similar to the Bootstrap bootstrap collapse panel? Why isn't the max-height transition working for me? How can I toggle the panel if it's checked, and have the panel collapse when d ...