Skip to content

Instantly share code, notes, and snippets.

@mnewt
Created December 6, 2012 20:28
Show Gist options
  • Save mnewt/4228037 to your computer and use it in GitHub Desktop.
Save mnewt/4228037 to your computer and use it in GitHub Desktop.
bootstrap tabs example
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Le styles -->
<link href="../bootstrap/css/bootstrap.css" rel="stylesheet">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
</head>
<body>
<div class="container">
<!-------->
<div id="content">
<ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
<li class="active"><a href="#red" data-toggle="tab">Red</a></li>
<li><a href="#orange" data-toggle="tab">Orange</a></li>
<li><a href="#yellow" data-toggle="tab">Yellow</a></li>
<li><a href="#green" data-toggle="tab">Green</a></li>
<li><a href="#blue" data-toggle="tab">Blue</a></li>
</ul>
<div id="my-tab-content" class="tab-content">
<div class="tab-pane active" id="red">
<h1>Red</h1>
<p>red red red red red red</p>
</div>
<div class="tab-pane" id="orange">
<h1>Orange</h1>
<p>orange orange orange orange orange</p>
</div>
<div class="tab-pane" id="yellow">
<h1>Yellow</h1>
<p>yellow yellow yellow yellow yellow</p>
</div>
<div class="tab-pane" id="green">
<h1>Green</h1>
<p>green green green green green</p>
</div>
<div class="tab-pane" id="blue">
<h1>Blue</h1>
<p>blue blue blue blue blue</p>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$('#tabs').tab();
});
</script>
</div> <!-- container -->
<script type="text/javascript" src="../bootstrap/js/bootstrap.js"></script>
</body>
</html>
@CyborgHead
Copy link

Works perfectly with Visual Studio 2013 ASP Template.

@imaginative
Copy link

Thanks for this. BTW, this code did not work for me. After an hour, I saw an error in the console saying I needed to use jQuery version 1.9.1 at least. I changed ther version number, and your code worked.

BTW, you don't need this:

<script type="text/javascript"> This will work: <script> This is valid code, and it's shorter and cleaner. Thought I'd give something back. Thanks!

@alishir
Copy link

alishir commented Mar 2, 2015

Thanks for your snippet, it seems it works without javascript snippet for tabs as mentioned in bootstrap page http://getbootstrap.com/javascript/#tabs-usage in Markup section.

@eka808
Copy link

eka808 commented Mar 8, 2015

thanks !

@vdquan
Copy link

vdquan commented Apr 9, 2015

Thanks!

@progonkpa
Copy link

Helped me though the JQuery version needed idd to be changed, thanks a bunch !

@pezzati
Copy link

pezzati commented Apr 25, 2015

NICE AND EASY!!!!
Thanks dude

@bliz937
Copy link

bliz937 commented Apr 26, 2015

Thanks!

@jrenouard
Copy link

Thanks! That's way better than the actual documentation...

@sudam
Copy link

sudam commented Jun 29, 2015

Thanks!

@nandankn
Copy link

nandankn commented Jul 3, 2015

Thank you!

@hjnaidu
Copy link

hjnaidu commented Jul 17, 2015

Thanks for this example.

@silversonicaxel
Copy link

excellent key example

@carlosh1989
Copy link

cool....! (Y)

@DaveJuel
Copy link

DaveJuel commented Aug 4, 2015

Thanks a lot.. it really saved time.!!

@arthurbryant
Copy link

Thanks a lot!

@craigmiller160
Copy link

Why is this not working for me? I literally copied and pasted the whole thing and it still doesn't work. I don't know javascript, btw, only HTML/CSS, so I can't tell if I'm screwing something up there. Still, though, like I said, I literally copied and pasted the code, and I can't get the tabs to switch. The cool looking UI is there, but the tabs won't switch.

@DomJones
Copy link

Hi all,
I have an issue with a similar page I am working on for work.
I'm pretty new to HTML and sort of picking it up as I go along and thrown myself into the deep end.

I am using nav-tabs but with 8 tabs in total.
My problem is that the last 2 tabs contents are displaying along the bottom of all the other tabs in IE.
Seems to be working fine in Chrome but cannot figure out what I have done wrong for is to display different in IE.
Any help would be appreciated, cheers

@venkataGoli
Copy link

@craigmiller160 I am pretty sure this has to with some imports not coming in. Just open u r developer tools and check. One more thing jQuery is coming from a CDN so you should have internet when u open this html page, make sure u have the interent connection. :)

@AlbertMN
Copy link

Awesome! Thank you!

@kayhan-swarup
Copy link

How come the href doesn't work?? I copied and paste it. still when i click on other tabs, nothing happens... why?

@grafixgeek
Copy link

The exact code above doesn't work. If you load a more recent version of jQuery (I used v1.12.3), you should be successful.

@vyamasanim
Copy link

grafixgeek - I am using jquery-2.2.4 and bootstrap 3.3.6. It worked for me

@Eric-Jalal
Copy link

you saved me an hour! Good job 👍

@briankip
Copy link

briankip commented Aug 1, 2016

You are doing God's work my son.

@ismendoza
Copy link

Why I don't need to add $('#tabs').tab(); to work ?
Only works adding the library jquery "<script jquery... ></script>"

@christoga
Copy link

Thank's for the gist bro!

@santosgabriel
Copy link

Thanks !

@hariharankgk
Copy link

Hi, Thanks,
But, I have a doubt, `Is it possible to link a particular tab from another page?

@ZengTianShengZ
Copy link

Thanks! very nice job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment