Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery change CSS after a certain amount of time

I have a navigation that, when one of it's nav items is clicked, will use jQuery to change it's z-index to 0. Then, after 2 seconds, I would like the z-index to be changed to 2.

I tried using delay() but apparently that doesn't work when changing the CSS.

like image 673
Robert Pessagno Avatar asked Dec 10 '10 17:12

Robert Pessagno


2 Answers

Use a setTimeout like this

$(elem).css('z-index','0');
setTimeout(function(){ $(elem).css('z-index','2'); },2000)
like image 186
Michael Gillette Avatar answered Nov 03 '22 00:11

Michael Gillette


In javascript you can use either setTimeout or setInterval to accomplish that

setTimeout("javascript statement",milliseconds);

http://www.w3schools.com/js/js_timing.asp

like image 26
wajiw Avatar answered Nov 03 '22 00:11

wajiw