Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNick Hennen
7,812 PointsI can't get Bootstrap tabs to work.
I think the code below should work but when I test it only the first tab "Home" is functioning.
<!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="bootstrap.css"> <link rel="javascript" type="text/javascript" href="bootstrap.min.js"> <title>Tabs for everyone</title> </head> <body>
<!-- Nav tabs -->
<ul class="nav nav-pills">
<li class="active"><a href="#home" data-toggle="tab">Home</a></li>
<li><a href="#profile" data-toggle="tab">Profile</a></li>
<li><a href="#messages" data-toggle="tab">Messages</a></li>
</ul>
<div id='content' class="tab-content">
<div class="tab-pane active" id="home">
<ul>
Example Text
</ul>
</div>
<div class="tab-pane" id="profile">
<ul>
Example text
</ul>
</div>
<div class="tab-pane" id="messages">
<ul>
Example Text
</ul>
</div>
</div>
</body> </html>
3 Answers
Nick Ocampo
15,661 PointsAdd this to your html file right before the closing body tag.
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
Nick Ocampo
15,661 PointsMake sure you're linking to the Bootstrap js file. If it's not linked right, you'll often see something about it on the Chrome Dev Tools console by hitting command + alt + j
Nick Hennen
7,812 PointsThank you, I check and I am got the error "Uncaught Error: Bootstrap's JavaScript requires JQuery". I linked to the java script using a script tag around src="bootstrap.min.js" . All my files are in the same directory for now so the file should be found.
Kevin Korte
28,148 PointsAre you including jQuery in your page, before the bootstrap js gets included?
Bootstrap needs jQuery 1.11.1 or 2.1.1 to work.
If you need to support IE8 you'll be stuck with the 1.11.1 version.
Nick Hennen
7,812 PointsI didn't include JQuery on the page. I thought that maybe having the bootstrap.js or bootstrap.min.js file was enough.
Nick Hennen
7,812 PointsNick Hennen
7,812 PointsThank you, I did not include JQuery in my page. After adding the first line of code it worked. Is there any difference in terms of usability or otherwise if JQuery is downloaded and locally hosted?
Nick Ocampo
15,661 PointsNick Ocampo
15,661 PointsThe difference isn't huge, but linking to a CDN is usually better. There's less latency, better caching, etc.
Kevin Korte
28,148 PointsKevin Korte
28,148 PointsThere is no difference in usability, however, it's usually a good idea to let a CDN host jQuery for you. Probably the biggest advantage to using Google's CDN for jQuery is that many websites also use it. So when a user hits your website, there is a high likelyhood that user's browser has already cached a copy of jQuery from google, and thus will use it's cached version instead of downloading it again. This will give your site a small bump in speed.
If your jQueryis locally hosted, even if their browser already has jQuery cached from Google's CDN, it'll download your locally hosted file.
Having a locally hosted jQuery as a fallback in the rare event the Google CDN is down isn't a bad idea though.