Boris Goryachev
Boris Goryachev

Reputation: 103

How to delay .trigger('click') with overlay from jquery tools

I am using Jquery tools, overlay effect and want to close it, if JSON response is OK, but i want to do it with a delay.

  $.ajax({
                //bla bla
                success: function(data){
                        var obj = jQuery.parseJSON(data);
                        if (obj.status=='OK')
                        {
                            $('#status').text('bla bla');
                            jQuery('.close').trigger('click');
                        }
                        else
                        {
                            $('#status').text('bla bla');                       
                        }
                    }
            }); 

so this - jQuery('.close').trigger('click'); must be executed after some time. Any ideas?

Upvotes: 10

Views: 30766

Answers (3)

Lex
Lex

Reputation: 1378

Not tested.

jQuery('.close').delay(500).trigger('click');

Upvotes: -4

TelegramSam
TelegramSam

Reputation: 2790

use setTimeout:

delay here is 1 second (1000 ms)

$.ajax({
                //bla bla
                success: function(data){
                        var obj = jQuery.parseJSON(data);
                        if (obj.status =='OK')
                    {
                        $('#status').text('bla bla');
                        setTimeout(function(){jQuery('.close').trigger('click');},1000);

                    }
                    else
                    {
                        $('#status').text('bla bla');                       
                    }
                }
        }); 

Upvotes: 6

David Tang
David Tang

Reputation: 93674

setTimeout() is a native JavaScript function designed for this purpose.

setTimeout(function () {
   jQuery('.close').trigger('click');
}, 1000);

The last number there is the delay time in milliseconds.

Upvotes: 26

Related Questions