jQuery autohide element after 5 seconds

前端 未结 8 1388
刺人心
刺人心 2020-11-29 17:53

Is it possible to automatically hide an element in a web page 5 seconds after the form loads using jQuery?

Basically, I\'ve got

相关标签:
8条回答
  • 2020-11-29 18:46

    Please note you may need to display div text again after it has disappeared. So you will need to also empty and then re-show the element at some point.

    You can do this with 1 line of code:

    $('#element_id').empty().show().html(message).delay(3000).fadeOut(300);
    

    If you're using jQuery you don't need setTimeout, at least not to autohide an element.

    0 讨论(0)
  • 2020-11-29 18:51

    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)
提交回复
热议问题