Home > Article > Web Front-end > How to make elements disappear after 3 seconds in jquery
Jquery method to make elements disappear after 3 seconds: 1. Use the delay() method to specify the operation delay time; 2. Use the hide() method to hide the element after the specified delay time. The syntax is " $(specified element).delay(3000).hide(300);”.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
jquery How to make elements disappear after 3 seconds
If you want to achieve the effect of elements disappearing after three seconds, you need to use the delay() method and hide() method.
The delay() method sets a delay for the execution of the next item in the queue.
The syntax is:
$(selector).delay(speed,queueName)
hide() method is used to hide elements.
Let’s take an example to see how to use the above two methods to make the element disappear after 3 seconds. The example is as follows:
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(function(){ $("#dianji").click(function(){ $("#disappare").delay(3000).hide(300); }); }) </script> </head> <body> <div id="content"> <button id="dianji">点击</button> <div id="disappare"> <p>点击3秒后会自动消失</p> </div> </div> </body> </html>
Output result:
Recommended related video tutorials: jQuery video tutorial
The above is the detailed content of How to make elements disappear after 3 seconds in jquery. For more information, please follow other related articles on the PHP Chinese website!