The function displays a message. After some time, the message closes, but remains in the DOM. And when you call the function again, the messages are accumulated and not deleted. How to get the newly created object and hang the delete function on it after some time?
I generate a random line for output and assign it to the output as id. But for some reason, the newly created objects do not want to remove (), if you call the function several times in a row (without waiting for the previous call to finish). How to be?
function message(message_text, message_type='success') { id=random_string(); //личная функция html='<div id="'+id+'" class="alert alert-'+message_type+'">\n' + ' <button type="button" class="close" data-dismiss="alert">×</button>\n' + ' '+message_text+' ' + '</div>'; jQuery('#message_box').prepend(html); if(message_type=='success') { $('#message_box #'+id).fadeTo(2000, 500).slideUp(500, function(){ jQuery('#message_box #'+id).remove(); }); } }