-1

I was exploring the basics of Bootstrap and everything seemed to worked fine(the very basic stuff, tables, col, etc.). However, I tried to make a carousel by following the example on the bootstrap website and it didn't work. The carousel appeared fine with everything but the next and prev buttons did nothing.

So I just copied the example on the website directly and the same thing happens, everything is there but non-functional. I was using the bootstrap files given to me by WebStorm but I changed it to the CDN links as a troubleshooting step to no avail.

I tried in Edge and Chrome too. [edit]I also tried a suggestion that I found on SO to change the anchor tags to button tags for the buttons but it didn't work[/edit]

Am I missing a dependency somewhere? I believe I have everything I need:

  • bootstrap.min.css
  • bootstrap.bundled.min.js
  • jquery.min.js

Thank you.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
    <title>Title</title>
</head>
<body>
  <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
      <ol class="carousel-indicators">
          <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
          <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
          <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
      </ol>
      <div class="carousel-inner">
          <div class="carousel-item active">
              <img class="d-block w-100" src="https://placeimg.com/1080/500/animals" alt="First slide">
              <div class="carousel-caption d-none d-md-block">
                  <h5>My Caption Title (1st Image)</h5>
                  <p>The whole caption will only show up if the screen is at least medium size.</p>
              </div>
          </div>
          <div class="carousel-item">
              <img class="d-block w-100" src="https://placeimg.com/1080/500/arch" alt="Second slide">
          </div>
          <div class="carousel-item">
              <img class="d-block w-100" src="https://placeimg.com/1080/500/nature" alt="Third slide">
          </div>
      </div>
      <button class="carousel-control-prev" data-target="#carouselExampleIndicators" role="button" data-slide="prev">
          <span class="carousel-control-prev-icon" aria-hidden="true"></span>
          <span class="sr-only">Previous</span>
      </button>
      <button class="carousel-control-next" data-target="#carouselExampleIndicators" role="button" data-slide="next">
          <span class="carousel-control-next-icon" aria-hidden="true"></span>
          <span class="sr-only">Next</span>
      </button>
  </div>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
</body>
</html>
Layne
  • 5
  • 3
  • You used wrongly named `data-` attributes on those buttons. You put `data-target` and `data-slide`, but as https://getbootstrap.com/docs/5.1/components/carousel/#with-controls shows, they need to be named `data-bs-target` and `data-bs-slide` – CBroe Apr 21 '22 at 14:28
  • _"So I just copied the example on the website directly and the same thing happens"_ - then you probably navigated into the documentation for BS 4 by mistake. – CBroe Apr 21 '22 at 14:30
  • @CBroe I'm face palming myself so hard right now. I used the link given by my teacher and he is indeed using Bootstrap 4.0 and I was on 5.0. Thank you! – Layne Apr 21 '22 at 14:37
  • FYI, Bootstrap 5 doesn't depend on jQuery and it's commonly held that jQuery should be avoided in modern applications as it's largely unnecessary. See https://youmightnotneedjquery.com. – isherwood Apr 21 '22 at 15:03
  • Does this answer your question? [Navbar dropdown (collapse) is not working in Bootstrap 5](https://stackoverflow.com/questions/65341620/navbar-dropdown-collapse-is-not-working-in-bootstrap-5) – isherwood Apr 21 '22 at 15:04

1 Answers1

0

Like @CBroe pointed out in the comment there was a version mismatch, the code was for Bootstrap 4.0 and the Bootstrap version I was using was 5.0.

Layne
  • 5
  • 3