DarkPresidentOfAmerica DarkPresidentOfAmerica - 4 years ago 144
HTML Question

Why do I need to add a link to JQuery in my HTML?

I have a web page copy of a bootstrap official demo/template page. Bootstrap needs JQuery. I know this. The template already has a link to the JQuery page.

However, in my page the NavBar menu is not working unless I add a second link to JQuery:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

Here is the unmodified Bootstrap page.

Here is my page.

Here is a diff view of the two pages.

My question is: why I have to add that line?

(Obviously I am a beginner with JS/bootstrap).


I think the problem is this JS file that is used in my bootstrap template.

Answer Source

A more specific answer If I may.

An answer like "you need jquery for bootstrap" isn't fully right cause you can still use it without JS but there are several features that require js/jquery.

According to the manual, the Navbar feature has dependency in jQuery, as follows:


Requires JavaScript

plugin If JavaScript is disabled and the viewport is narrow enough that the navbar collapses, it will be impossible to expand the navbar and view the content within the .navbar-collapse.

The responsive navbar requires the collapse plugin to be included in your version of Bootstrap.

So if you want your navbar to be responsive (= collapse) you need to include that collapse js plugin which depends on jQuery library.


In the original template the jquery script is being included. Just instead of a CDN file (from google's library) it's a local copy of an old version.

    <!-- /.container -->

    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>



Please notice that different versions of bootstrap requires different versions of jQuery. So a newer version of bootstrap might require a newer version of jQuery.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download