Bootstrap Tutorial - Toggle div block by button








The following code shows how to toggle div block by button.

Example

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'
  src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css"
  href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css">
<script type='text/javascript'>
$(function(){<!--   w  ww .  j a v  a  2  s .  c  om-->
    $('button').click(function(){
        $(this).text(function(i,old){
            return old=='+' ?  '-' : '+';
        });
    });
});
</script>
</head>
<body>
  <div class="row-fluid summary">
    <div class="span11">
      <h2>MyHeading</h2>
    </div>
    <div class="span1">
      <button class="btn btn-success" data-toggle="collapse"
        data-target="#intro">+</button>
    </div>
  </div>
  <div class="row-fluid summary">
    <div id="intro" class="collapse">Here comes the text...</div>
  </div>
</body>
</html>

Click to view the demo