Bootstrap Tutorial - Create alert block with Javascript








The following code shows how to create alert block with Javascript.

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">
<script type='text/javascript'
  src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){<!--from   ww w .  j  a  v a2 s  .c o m-->
function showAlert(message, alertType) {
  $('#alert').html("<div class='alert alert-"+alertType+"'>"+message+"</div>");
  $('#alert').show();
}
showAlert('Alert.', 'success');
});//]]>  
</script>
</head>
<body style='margin:30px'>
  <div id='alert' class='hide'></div>
</body>
</html>

Click to view the demo