5

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.

Robert Pessagno
  • 519
  • 2
  • 7
  • 19
  • Do you just want the element to disappear and then after 2 seconds, reappear? There's better ways to make things disappear and reappear. like jQuery.show()/.hide() – shoebox639 Dec 10 '10 at 17:50
  • Nope, I just wanted to change the z-index because it causes the links to be unclickable, but still visible, for 2 seconds – Robert Pessagno Dec 10 '10 at 18:25

2 Answers2

13

Use a setTimeout like this

$(elem).css('z-index','0');
setTimeout(function(){ $(elem).css('z-index','2'); },2000)
2

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

setTimeout("javascript statement",milliseconds);

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

wajiw
  • 12,239
  • 17
  • 54
  • 73