How to hide a element automaticaly after few seconds using jQuery

By | July 17, 2015

How to hide a element automaticaly after few seconds using jQuery

While developing a web application in some cases we show some alert messages, success messages or some information to the users. After showing these type of messages users has to close the information box manually. In this tutorial let’s see how to hide a element automaticaly after few seconds using jQuery.

Lets say that we want to hide the following div after 5 seconds.

<div id=”successMessage”>Project saved successfully!</div>

To do this we can use jQuery hide() function and delay() functions

hide() – Hides the matched elements.

Ex: $( ".target" ).hide();

delay() – Set a timer to delay execution of subsequent items in the queue.

Ex: $( "#foo" ).delay( 800 ).fadeIn( 400 );

Okay now continuing to our tutorial we have to use both of these functions with our target element.

$('#successMessage').delay(5000).hide();

Adding above line to your code will hide a element automaticaly after 5 seconds.

🔥0

One thought on “How to hide a element automaticaly after few seconds using jQuery

  1. Philomena

    Your website can go viral, you need some initial traffic only.
    But how to get initial traffic??? Search in google for: Leaghk’s method to go viral

    Reply

Leave a Reply