test
test

Reputation: 18198

How to delay an event in jQuery?

In jQuery can you do something after you press a button and the timer starts to go from 3 seconds down to 0?

Like you have a button. You press it. 3 Seconds go by and bam.. an event fires.

Upvotes: 1

Views: 273

Answers (3)

Bjoern
Bjoern

Reputation: 16314

You can use the .delay()-function.

They have a nice example in the documentation about this, which fits exactly to your question.

$("button").click(function() {
  $("yourelement").delay(3000).fadeIn(400);
});

Upvotes: 1

Hemant Metalia
Hemant Metalia

Reputation: 30698

you can use .delay() refer this

Upvotes: 1

talnicolas
talnicolas

Reputation: 14051

The delay() function (doc) :

Description: Set a timer to delay execution of subsequent items in the queue.

For your example:

$("button").click(function() {
    $("[element]").delay(3000).fadeOut("slow");
});

Upvotes: 6

Related Questions