Bootstrap Tutorial - Create Collapsible Element via Data Attributes








The following code shows how to create Collapsible Element via Data Attributes.

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>
<style type="text/css">
p {<!-- w  ww.j  a v  a2  s.co  m-->
  background: #F9F9F9;
  border: 1px solid #E1E1E8;
  margin: 10px 0;
  padding: 8px;
}

.bs-example {
  margin: 20px;
}
</style>
</head>
<body>
  <div class="bs-example">
    <!-- Trigger Button HTML -->
    <input type="button" class="btn btn-primary" data-toggle="collapse"
      data-target="#toggleDemo" value="Toggle Button">
    <!-- Collapsible Element HTML -->
    <div id="toggleDemo" class="collapse in">
      <p>
        This is a simple example of expanding and collapsing individual
        element via JavaScript. Click on the <b>Toggle Button</b> button to
        see the effect.
      </p>
    </div>
  </div>
</body>
</html>

Click to view the demo