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

I am using Jquery tools, the overlay effect and want to close it if the 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 is jQuery ('. close'). trigger ('click'); should be done after a while. Any ideas?

+8
jquery ajax overlay
source share
3 answers

setTimeout() is a built-in JavaScript function designed for this purpose.

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

The last number is the delay time in milliseconds.

+23
source share

use setTimeout:

The delay 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'); } } }); 
+6
source share

Not tested.

 jQuery('.close').delay(500).trigger('click'); 
-3
source share

Source: https://habr.com/ru/post/650041/


All Articles