tags:

views:

68

answers:

2

I have the following code that triggers two functions whenever a button is clicked. However it only fires the functions once. If i click it again, it does nothing. I need to reset this queue so it fires the functions everytime I click the button.

Also, I'm only doing this so I can delay the functions from be fired 1000ms - is there another way to do this?

$('#play').click(function() { 
// other code..

$(this).delay(1000).queue(function(){ countHourly(); countFlights() });

});
+2  A: 

jQuery.delay() is best for delaying between queued jQuery effects and such, and is not a replacement for JavaScript's native setTimeout function, which may be more appropriate for certain use cases. http://api.jquery.com/delay/

I suggest you use the setTimeout function in this case

$('#play').click(function() { 
  setTimeout(function(){ countHourly(); countFlights() }, 1000);
});
Tomh
A: 

Set a timer to delay execution of subsequent items in the queue. .delay()

$(this).delay(1000).queue(function(){ countHourly(); countFlights() });// delay 1000 would just happen if $(this) is being animated before .delay(1000)...

I would suggest you use window.setTimeout()

Reigel