You can use stop, and add function inside fadeOut() to add the html msg like this
function alerts(msg) {
$('.msg-alert').stop().fadeOut(500, function () {
$('.msg-alert').html(msg)
}).fadeIn(500)
}
Update
You can use clearInterval() and setTimeout like this
var tOut = null;
function alerts(msg) {
clearTimeout(tOut);
$this = $('.msg-alert');
$this.html(msg).fadeIn(500);
tOut = setTimeout(function () {
$this.fadeOut(500);
}, 2000);
}