Reputation: 875
I know there are a lot of questions like this on Stack Overflow and I've looked at them but my dropdown menu still isn't working.
Here's my code:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<ul class="nav pull-left">
<li><a href="#myModal" class="dropdown-toggle" data-toggle="modal" data-keyboard="false" data-backdrop="static">Login</a></li>
<li class="dropdown" id="accountmenu">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">My Account<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Login</a></li>
<li><a href="#">Register</a></li>
</ul>
</li>
</div>
</div>
</div>
What's wrong with it?
EDIT
So the drop down menu is now working with the answer posted to this question. However if I include the scripts mentioned over there the modal window stops working. And when I comment those entries it starts working again.
Here's the code for my modal window:
<div class="modal hide" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
X</button>
<h3 id="myModalLabel">
Enter your Credentials</h3>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="email" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<a href="news.php" class="btn btn-primary">Login</a>
<a href="registration.php" class="btn btn-primary">Sign up</a>
</div>
</div>
</form>
</div>
</div>
And the JavaScript for the trigger:
$('#myModal').on('hide',function(){
$('.nav > li > a.modal-open-li').removeClass('modal-open-li');
});
Upvotes: 11
Views: 54131
Reputation: 39
In my case, there was a component over my drop down button, and it took too long for I take note. Noob error, but it may helps somebody.
Upvotes: -1
Reputation: 49
In my case the problem was with version of jQuery. In bootstrap.js v3.3.6
if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1) || (version[0] > 2)) {
throw new Error('Bootstrap\'s JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3')
}
Note: 'Bootstrap\'s JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3'
I replaced the code of local jQuery file with jQuery-1.11.3.js and it starts working.
Hope it will work for you as well.
Upvotes: 0
Reputation: 10712
Seems to work fine in jsFiddle, here is an example http://jsfiddle.net/2hGuv/
You must remember to import the js file. here is the code with the following files imported: http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<ul class="nav pull-left">
<li><a href="#myModal" class="dropdown-toggle" data-toggle="modal" data-keyboard="false" data-backdrop="static">Login</a>
</li>
<li class="dropdown" id="accountmenu"> <a class="dropdown-toggle" data-toggle="dropdown" href="#">My Account<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Login</a>
</li>
<li><a href="#">Register</a>
</li>
</ul>
</li>
</div>
</div>
</div>
Upvotes: 9
Reputation: 2208
Check if you have this in js files: $('.dropdown-toggle').dropdown();
Check if you have something like this with this sequence:
<script src="jquery.js"></script>
<script src="bootstrap.js"></script>
<script type="text/javascript"> $(document).ready(function () { $('.dropdown-toggle').dropdown(); }); </script>
check this: Bootstrap drop-down menus and tabbable tabs on Docpad
Upvotes: 11
Reputation: 520
For mine it was because of the order of adding scripts was not right , it should be like this :
<script src="Scripts/jquery-1.9.1.min.js"></script>
<script src="Scripts/bootstrap.min.js"></script>
Upvotes: 2
Reputation: 111
Adding this in my ready function fixed the problem for me
$('.dropdown-toggle').dropdown();
Upvotes: 11
Reputation: 170
I had a similar problem. And the cause was the wrong order of js files in head tag. Correct order is the jquery.min.js first than bootstrap.min.js
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
Upvotes: 17
Reputation: 2612
For anyone still experiencing this problem. I found that I was including the bootstrap js files twice (I had split my header, body and footer files and had not realised I was including them both in the footer and header.
Might help someone.
Upvotes: 19