Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap navbar dropdown not working

So I'm trying to get the dropdown in the navbar from Twitter Bootstrap to work, and I'm having some problems.

Here's my html:

<ul class="nav">
  <li class="active"><%= link_to 'Home', root_path %></li>
  <li><a href="#">Forums</a></li>
  <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">World</a>
    <ul class="dropdown-menu">
      <li><%= link_to 'Current', current_path %></li>
      <li><%= link_to 'All', all_path %></li>
    </ul>
  </li>
</ul>

And I also have this in the <head>:

<script type="text/javascript" src="http://twitter.github.com/bootstrap/assets/js/bootstrap-dropdown.js"></script> 

It's just not working, can anyone see anything wrong with it?

like image 835
Cristiano Avatar asked Sep 14 '26 05:09

Cristiano


2 Answers

You are referring to a wrong JS file.

Instead of your <script> tag you use, use the following:

<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">

<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>

You can read about it here

At the <ul> class definition, add the relevant nav you wish to use:

<ul class="nav nav-tabs">

-----------------------------^^

or <ul class="nav nav-pills">

You can also directly link to bootstrap-dropdown.js through as per your comment, but nevertheless you'd need bootstrap css and js included (I also updated the fiddle): https://netdna.bootstrapcdn.com/twitter-bootstrap/2.0.4/js/bootstrap-dropdown.js

See fiddle

Also - I see that you use RoR, so make sure it's not a RoR issue on top of the missing JS file.

like image 170
Leon Avatar answered Sep 16 '26 09:09

Leon


I have the same issue with bootstrap drop-down(in rails). I resolved the issue by removing the //= require_tree . from application.js. And got worked.

like image 28
Ravi Kumar SIngh Avatar answered Sep 16 '26 10:09

Ravi Kumar SIngh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!