Home > Web Front-end > Front-end Q&A > How to make elements disappear after 5 seconds in jquery

How to make elements disappear after 5 seconds in jquery

WBOY
Release: 2022-06-02 10:11:44
Original
1805 people have browsed it

Method: 1. Use the delay and fadeOut methods, the syntax is "element object.delay(5000).fadeOut()"; 2. Use the setTimeout and hide methods, the syntax is "setTimeout(function(){element object. hide();},5000)".

How to make elements disappear after 5 seconds in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

jquery makes the element disappear after 5 seconds

Method 1: Use the .delay() method

delay() method to delete the next element in the queue The execution of the item sets a delay.

Syntax

$(selector).delay(speed,queueName)
Copy after login

The example is as follows:

Set id="myElem" to hide after showing for 5 seconds.

$("#myElem").show().delay(5000).fadeOut();
Copy after login

How to make elements disappear after 5 seconds in jquery

Method 2. Use setTimeout() method:

setTimeout() is a method belonging to window. This method is used Calls a function or calculated expression after a specified number of milliseconds.

hide() method hides the selected elements.

Tip: This is similar to the CSS property display:none.

Examples are as follows:

setTimeout(function() { $("#myElem").hide(); }, 5000);
Copy after login

How to make elements disappear after 5 seconds in jquery

Video tutorial recommendation: jQuery video tutorial

The above is the detailed content of How to make elements disappear after 5 seconds in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template