Jquery prompt message display automatically disappeared after the specific implementation

  • 2020-03-30 00:57:04
  • OfStack

It is often necessary to make a prompt message display for a few seconds and then automatically disappear. Previously, setTimeout was used to implement, but it is not good to find that there are multiple setTimeout on the page. Today I found two very easy ways.
Method one:
$("#errormsg").html(" Your message entered incorrectly. Please try again !").show(300).delay(3000).hide(300); 

Method 2:
$("#errormsg").html("ok").hide(3000);//This is disappearing
$("#errormsg").html("ok").fadeTo(3000).hide(); //This is to make it show for 5 seconds (without actually changing the opacity) and then hide

Related articles: