NullVoxPopuli
NullVoxPopuli

Reputation: 65143

jQuery: how do I get a div to go away after 1 second? (jQuery 1.3.2)

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

Upvotes: 0

Views: 435

Answers (3)

Hristo
Hristo

Reputation: 46497

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.

Upvotes: 2

Christian Smorra
Christian Smorra

Reputation: 1754

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^^

Upvotes: 1

Adam
Adam

Reputation: 44939

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

setTimeout(function(){$('div#divID').hide();},1000);

Upvotes: 4

Related Questions