Show tab in Javascript

Description

The following code shows how to show tab in Javascript.

Example


<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet"
  href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<link rel="stylesheet"
  href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
<script type="text/javascript"
  src="http://code.jquery.com/jquery.min.js"></script>
<script
  src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){ <!-- www .  j av  a 2s . c  o m-->
    $("#myTab a").click(function(e){
      e.preventDefault();
      $(this).tab('show');
    });
});
</script>
<style type="text/css">
.bs-example {
  margin: 20px;
}
</style>
</head>
<body>
  <div class="bs-example">
    <ul class="nav nav-tabs" id="myTab">
      <li class="active"><a href="#sectionA">Section A</a></li>
      <li><a href="#sectionB">Section B</a></li>
      <li class="dropdown"><a data-toggle="dropdown"
        class="dropdown-toggle" href="#">Dropdown <b class="caret"></b></a>
        <ul class="dropdown-menu">
          <li><a href="#dropdown1">Dropdown1</a></li>
          <li><a href="#dropdown2">Dropdown2</a></li>
        </ul></li>
    </ul>
    <div class="tab-content">
      <div id="sectionA" class="tab-pane fade in active">
        <h3>Section A</h3>
        <p>Aliquip placeat salvia cillum iphone. Seitan aliquip quis
          cardigan american apparel, butcher voluptate nisi qui. Raw denim
          you probably haven't heard of them jean shorts Austin. Nesciunt
          tofu stumptown aliqua, retro synth master cleanse. Mustache cliche
          tempor, williamsburg carles vegan helvetica. Reprehenderit butcher
          retro keffiyeh dreamcatcher synth.</p>
      </div>
      <div id="sectionB" class="tab-pane fade">
        <h3>Section B</h3>
        <p>Vestibulum nec erat eu nulla rhoncus fringilla ut non neque.
          Vivamus nibh urna, ornare id gravida ut, mollis a magna. Aliquam
          porttitor condimentum nisi, eu viverra ipsum porta ut. Nam
          hendrerit bibendum turpis, sed molestie mi fermentum id. Aenean
          volutpat velit sem. Sed consequat ante in rutrum convallis. Nunc
          facilisis leo at faucibus adipiscing.</p>
      </div>
      <div id="dropdown1" class="tab-pane fade">
        <h3>Dropdown 1</h3>
        <p>WInteger convallis, nulla in sollicitudin placerat, ligula
          enim auctor lectus, in mollis diam dolor at lorem. Sed bibendum
          nibh sit amet dictum feugiat. Vivamus arcu sem, cursus a feugiat
          ut, iaculis at erat. Donec vehicula at ligula vitae venenatis. Sed
          nunc nulla, vehicula non porttitor in, pharetra et dolor. Fusce nec
          velit velit. Pellentesque consectetur eros.</p>
      </div>
      <div id="dropdown2" class="tab-pane fade">
        <h3>Dropdown 2</h3>
        <p>Donec vel placerat quam, ut euismod risus. Sed a mi suscipit,
          elementum sem a, hendrerit velit. Donec at erat magna. Sed
          dignissim orci nec eleifend egestas. Donec eget mi consequat massa
          vestibulum laoreet. Mauris et ultrices nulla, malesuada volutpat
          ante. Fusce ut orci lorem. Donec molestie libero in tempus
          imperdiet. Cum sociis natoque penatibus et magnis dis parturient.</p>
      </div>
    </div>
  </div>
</body>
</html>

Click to view the demo





















Home »
  Bootstrap »
    Example »




Accordion
Alert
Auto Complete
Badge
Breadcrum
Button
Carousel
Collapse
Dialog
Dropdown
Form
Icon
Jumbotron
Label
Layout
List
List Group
Media
Navigation Bar
Pager
Page Header
Panel
Paragraph
Pills
Popover
ProgressBar
ScrollSpy
Switch
Tab
Table
Thumnail
Tooltip
Tree
Well