How to hide a flash message after a few seconds?
In my application, a user can send a request to another user. So after successfully posting the call, I am showing one flash message for the same. But now I want to hide this message after a few seconds. So I wrote the following code:
$(document).ready(function(){
setTimeout(function() {
$("#successMessage").hide('blind', {}, 500)
}, 5000);
});
<div id="successMessage" style="text-align:center; width:100%">
<FONT color="green">
<%if flash[:alert]=="Your challenge is posted successfully."%>
<h4><%= flash[:alert] if flash[:alert].present? %>
<%end%>
</font>
</div>
But this code doesn't hide the "successMessage" div.
+7
source to share
3 answers
You can use the jQuery API delay for this .
$(document).ready(function(){
$("#successMessage").delay(5000).slideUp(300);
});
+5
source to share