Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
152
rated 0 times [  155] [ 3]  / answers: 1 / hits: 28510  / 13 Years ago, thu, february 16, 2012, 12:00:00

I need a simple way or pausing a few seconds before the next line of code is executed.



So I have:



$('.myClass').show();

//WAIT FOR 5 SECONDS HERE

$('.myClass').hide();

More From » jquery

 Answers
17

setTimeout:



$('.myClass').show();
window.setTimeout(function (){$('.myClass').hide(); }, 5000);


$('.myClass').show().delay(5000).hide(); 




Only subsequent events in a queue are delayed; for example this will
not delay the no-arguments forms of .show() or .hide() which do not
use the effects queue.




docs



In order to use delay you have to use duration so it will use the queue:



$('.myClass').show().delay(5000).hide(0); 


JSFiddle DEMO



Thanks @am not i am! (again...)


[#87418] Wednesday, February 15, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zoiel

Total Points: 692
Total Questions: 90
Total Answers: 89

Location: Rwanda
Member since Thu, Feb 10, 2022
2 Years ago
;