I'm trying to send a message to the user using jQuery and hide it automatically after a few seconds. This procedure occurs perfectly unless the event occurs less than the time to hide the message, causing the message to not synchronize with the event. To perform a test click multiple times on the link to follow the result.
Follow the example:
$('#id').click(function(){
$("#msg").html('<div class="alert alert-success">ALERTA</div>').hide().fadeIn();
$("#msg").delay(5000).fadeOut();
});
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://getbootstrap.com/dist/css/bootstrap.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<a href="#" id="id" class="btn">alerta</a>
<div id="msg"></div>
NOTE: Any other solution to solve this problem is welcome.