How to hide flash message after few seconds?

前端 未结 4 677
鱼传尺愫
鱼传尺愫 2020-12-17 18:34

In my application user can post challenge for other user. So after successful posting a challenge I am displaying one flash message for the same. But now I want to hide this

相关标签:
4条回答
  • 2020-12-17 18:43

    Someone posted a similar question to stackoverflow with this solution:

    <script type="text/javascript">window.setTimeout("document.getElementById('successMessage').style.display='none';", 2000); </script>
    
    <div id="successMessage"> bla bla bla
    </div>
    

    I'd share the link but I can't find it anymore. Thanks for the help, though, mystery human!

    0 讨论(0)
  • 2020-12-17 18:51

    Some times it's not enough to only setting display of box to none it's better to completely remove it. as follows:

    setTimeout(function() {
        $('.alert-box').remove();
    }, 30000); 
    
    0 讨论(0)
  • 2020-12-17 18:55

    You can use the delay jQuery API to achieve this.

    $(document).ready(function(){
        $("#successMessage").delay(5000).slideUp(300);
    });
    
    0 讨论(0)
  • 2020-12-17 18:57

    You can try :

    setTimeout(function() {
        $('#successMessage').fadeOut('fast');
    }, 30000); // <-- time in milliseconds
    

    If you used this then your div will be hide after 30 sec.I also tried this one and it worked for me.

    0 讨论(0)
提交回复
热议问题