thepersonwho
thepersonwho

Reputation: 85

html - Bootstrap 3 collapse button appears but no effect when clicked?

I'm trying to make it so that when I click my collapse button, the two labels will appear, but it's not happening even though the data-target and id (colnav) of the navbar are same.

<nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#colnav">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>                        
          </button>

          <a class="navbar-brand" href="#">
            <%= image_tag("iinfo.png", :alt => "INFOMAN") %>
          </a>
        </div>

      <div class="collapse navbar-collapse" id="colnav">

            <ul class="nav navbar-nav navbar-right" >
              <li class="color-me">
                <a href="#" style="color:red">
                  Contact Us
                </a>
              </li>
              <li>
                <% if current_user %>
                <%= link_to 'Logout', session_path("new") , method: "delete"%>
                <% end %>
              </li>
            </ul> 
      </div><!--/.navbar-collapse -->

    </div>
</nav>

Upvotes: 0

Views: 51

Answers (2)

Daniel Goh
Daniel Goh

Reputation: 26

Bootstrap requires jQuery for its effects. If you're requiring bootstrap via its CDN, you need to ensure that jquery is loaded in your application.html.erb. See this official template.

<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <h1>Hello, world!</h1>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

However, if you're requiring bootstrap through the bootstrap gem, then you need to ensure that gem 'jquery-rails' is in your gemfile, and your application.js manifest file requires jquery.

See the gem documentation for correct installation details.

Hope this helps!

Upvotes: 1

Abiud Orina
Abiud Orina

Reputation: 1231

This issue usually happens when you haven't linked your bootstrap.min.js file correctly.

Upvotes: 0

Related Questions