User288213138 posted
Hi UmerFaiz001,
I would like to hide the alert after few seconds
You can try to use fadeTo() and slideUp() method to gradually changes the opacity, for selected elements, to a specified opacity (fading effect).
The code:
<script type="text/javascript">
function ShowMessage(message, messagetype) {
var cssclass;
switch (messagetype) {
case 'Success':
cssclass = 'alert-success'
break;
case 'Error':
cssclass = 'alert-danger'
break;
case 'Warning':
cssclass = 'alert-warning'
break;
default:
cssclass = 'alert-info'
}
$('#alert_container').append('<div id="alert_div" style="margin: 0 0.5%; -webkit-box-shadow: 3px 4px 6px #999;" class="alert fade in ' + cssclass + '"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a><strong>' + messagetype + '!</strong> <span>' + message + '</span></div>');
$("#alert_container").fadeTo(2000, 500).slideUp(500, function () {
$("alert_container").slideUp(500);
});
}
</script>
The result:

Best regards,
Sam