Bootstrap Tutorial - Add alert message through Javascript code








The following code shows how to add alert message through Javascript code.

Example

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<link rel="stylesheet" type="text/css"
  href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css">
<!--from  w  w w . java  2 s.c o  m-->
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
      function showAlert(message) {
        $('#alert').html("<div class='alert alert-error'>"+message+"</div>");
        $('#alert').show();
      }
      showAlert('Please have a look at the database.');
});
</script>
</head>
<body>
  <div id='alert' class='hide'></div>
</body>
</html>

Click to view the demo