1

I am still new to web development, and I admit I am not good at designing, so I relied heavily on Bootstrap's nice CSS for styling tables, dropdowns ,etc., .How do you link your Bootstrap files in main layout?So far Bootstrap works nicely in my newly created site, but I have one problem, Google's developer's console tells that I have error in my layout.html

Uncaught Error: Bootstrap's JavaScript requires jQuery

This is how I linked Bootstrap css/js in my layout,

<head><link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"></head>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

So I tried this way

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

Now the error is gone.The styling in table, pager still works, but Bootstrap's dropdown in navbar no longer works.How do you fix this?

<div class="navbar navbar-default navbar-static-top" role="navigation">
                <div class="container">
                    <div class="navbar-header">
                        <a class="navbar-brand" href="{{ path('voters_register') }}">
                            Register Here
                        </a>
                        <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>
                    <div class="navbar-collapse collapse">
                        <ul class="nav navbar-nav">
                            <li class="active"><a href="{{path('homepage')}}">Home</a></li>
                            <li><a href="{{ path('about') }}">About</a></li>
                            <li><a href="{{path('contact')}}">Contact</a></li>
                            <li class="dropdown">//the problem is here
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Stats<span class="caret"></span></a>
                                <ul class="dropdown-menu">
                                    <li><a href="{{path('voters_groups')}}">Supporter's Groups</a></li>
                                    <li><a href="{{path('voters_island')}}">Statistics</a></li>
                                    <li><a href="{{path('search_city')}}">Search</a></li>
                                    <li><a href="{{path('voter_graph')}}">Graphs</a></li>
                                    <li><a href="{{path('voters_list')}}">Lists of Supporters</a></li>
                                    <li><a href="{{path('voters_messages')}}">Supporter's Messages</a></li>
                                    <li><a href="{{path('voters_register')}}">Register Here</a></li>
                                    <li><a href="#">Something else here</a></li>
                                    <li role="separator" class="divider"></li>
                                    <li class="dropdown-header">Nav header</li>
                                    <li><a href="#">One more separated link</a></li>
                                </ul>
                            </li>
                        </ul>
                      <.........other markups....>
2
  • Is Bootstrap 3.3.5 compatible with jQuery 1.11.3 (edit: yes, requires 1.9.1 or better). Also, so you know, with this code you're embedding JavaScript (not CSS) in your page. Have you also included the CSS links? Commented Aug 23, 2015 at 4:58
  • I'm not able to reproduce the problem with the dropdown not working. Can you provide a jsfiddle to demonstrate the problem? Commented Aug 23, 2015 at 5:17

5 Answers 5

3

I also had that problem before, changing your configuration like this

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

Will resolve the problem. I don't know why the link from JQuery.com

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

Will cause an error in developer's console but, still work anyway.Hoep it helps

Sign up to request clarification or add additional context in comments.

Comments

1

Get rid of the 'https:' from the boostrap JS file, you might be causing an SSL conflict by loading the page over http.

Edit: Why did I get downvoted? Relative URL's are a thing... even the top answer is using them...

Comments

0

Here you can find an example how to link files Bootstrap basic template

Did you include stylesheets? If so show your navbar code, probably mistake is there.

2 Comments

Is there any error when you click on dropdown link?
the error is still there.But it is already fixed now as answered by user Ian Russel Adem
0

please use this link tag

<head>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
 </head>

Comments

0
  1. There are many code snippets available, make sure your code matches the version of bootstrap your loading.
  2. If, if jquery is required bring it in first then the bootstrap.
  3. Finally, (not-always) but in most cases its better to put your javascript at the bottom, that is just before your closing tag of body:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.