We often need to display prompt messages to users and have them disappear after a specified number of seconds. Here we demonstrate how to use jQuery to hide an element after a specified number of seconds (5 seconds).

Method 1: Use the .delay() method

Settingsid="myElem"Hide after being displayed for 5 seconds.

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

Method 2: Use the setTimeout() method:
setTimeout(function() { $("#myElem").hide(); }, 5000);