Bootstrap Tutorial - Show closable alert box








The following code shows how to show closable alert box.

Example

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-git2.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'>
$(window).load(function(){<!--from   w  w  w.  ja  va 2s . c  om-->
    $('#the-thing-that-opens-your-alert').click(function () {
      $('#le-alert').addClass('in'); 
    });
    $('.close').click(function () {
      $(this).parent().removeClass('in');
    });
});
</script>
</head>
<body>
  <a id="the-thing-that-opens-your-alert" href="#">Open my alert</a>
  <div id="le-alert" class="alert alert-warn alert-block fade">
    <button href="#" type="button" class="close">&times;</button>
    <h4>Alert title</h4>
    <p>Roses are red, violets are blue...</p>
  </div>
</body>
</html>

Click to view the demo