Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Collapsible Menu not working

I'm having an issue getting the collapsible navigation bar to load on a page - the button appears when you shrink the screen, but when I click on it, nothing happens. The console isn't throwing me any errors, so I'm assuming there must be something wrong with my css/javascript, but I don't really know what.

If it matters, I'm linking through with the Bootstrap CDN on my page - I don't know if that requires me to include the plugins manually or not (I don't think it would but I'm not sure).

The following is my HTML and Javascript link-ins:

 <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="navbar-collapse">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
  </div>

  <!-- Collect the nav links, forms, and other content for toggling -->
  <div class="collapse navbar-collapse">
    <ul class="nav navbar-nav">
      <li class="active"><a href="/">Home</a></li>
      <li><a href="#">Operation Pulse</a></li>
      <li><a href="#">Forum</a></li>
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Media <b class="caret"></b></a>
        <ul class="dropdown-menu">
          <li><a href="news/">News &amp; Updates</a></li>
          <li><a href="#">Indie Pulse</a></li>
          <li><a href="#" style="text-transform: lowercase;">rec</a></li>
          <li><a href="#">Geeks and Giggles</a></li>
          <li class="divider"></li>
          <li><a href="#">Podcasts</a></li>
        </ul>
      </li>
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Info <b class="caret"></b></a>
        <ul class="dropdown-menu">
          <li><a href="#">About Us</a></li>
          <li><a href="#">FAQ</a></li>
          <li><a href="crew.php">Crew</a></li>
          <li><a href="contact.php">Contact Us</a></li>
        </ul>
      </li>
    </ul>
  </div>

JS

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet">
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="//code.jquery.com/jquery.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js" type="text/javascript"></script>
like image 858
secondubly Avatar asked Nov 11 '13 00:11

secondubly


People also ask

How do I create a collapsible menu in bootstrap?

Just add data-toggle="collapse" and a data-target to the element to automatically assign control of one or more collapsible elements. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element.

How does Bootstrap collapse work?

Bootstrap's collapse class exposes a few events for hooking into collapse functionality. This event fires immediately when the show instance method is called. This event is fired when a collapse element has been made visible to the user (will wait for CSS transitions to complete).

Which BS 5 attribute and value is used to create a collapse system?

To control (show/hide) the collapsible content, add the data-bs-toggle="collapse" attribute to an <a> or a <button> element. Then add the data-bs-target="#id" attribute to connect the button with the collapsible content (<div id="demo">).

What is data BS toggle in HTML?

The data-toggle is an HTML-5 data attribute defined in Bootstrap. The advantage of using this is that, you can select a class or an id and hook up the element with a particular widget.


Video Answer


1 Answers

Change the data-target= in the button to.. .navbar-collapse

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
like image 191
Zim Avatar answered Oct 31 '22 18:10

Zim