tags:

views:

53

answers:

3

Is there a way to hide a div after 1 second?

EDIT:

setTimeout(function(){
    $j('.flotymessage').fadeOut(300);
    },1000);

doesn't work =\ .floatymessage is a div

+3  A: 

Use setTimeout to hide after one second (1000 milliseconds).

setTimeout(function(){$('div#divID').hide();},1000);
Adam
why doesn't this work? setTimeout(function(){ $j('.flotymessage').fadeOut(300); },1000);
DerNalia
@DerNalia - In your other questions, you have it spelled `floatymessage` not `flotymessage`.
patrick dw
oh dear.. how could I have messed that up. haha. thanks.
DerNalia
+1  A: 

The jQuery delay() function is the way to go. The parameter to delay() is in milliseconds so you need 1000 ms to get 1s.

$('div.flotymessage').delay(1000).hide("slow"); // hide it slowly
$('div.flotymessage').delay(1000).hide(1); // hide it after 1 ms (pretty much instantly)

An alternative to hide()ing your <div> is to assign it a new class that would have the CSS ready for the hiding. Let me know if you need me to elaborate on that.

Hope that helps.

Hristo
I actually saw this, but I have jQuery 1.3.2, I wall add that to the title
DerNalia
This will not work, because `.delay()` only works ahead of calls that have an animation queue. For example, it would work if you did `$('div.flotymessage').delay(1000).hide("slow");`
patrick dw
@patrick dw... thanks for the correction. I updated my answer.
Hristo
+1  A: 

if the above solution doesnt work for you (cant tell why, it should work) you can always try .delay so

setTimeout(function(){
$j('.flotymessage').fadeOut(300);
},1000);

would become

$j('.flotymessage').delay(1000).fadeOut(300);

€: im sorry i was too slow^^

Christian Smorra