setTimeout() is not waiting [duplicate] setTimeout() is not waiting [duplicate] javascript javascript

setTimeout() is not waiting [duplicate]


setTimeout(countdown(element), 1000); executes your function with that argument and passes the result into setTimeout. You don't want that.

Instead, execute an anonymous function that calls your function:

setTimeout(function() {    countdown(el);  // You used `el`, not `element`?}, 1000);


It is because setTimeout is asynchroneous. Try this:

setTimeout(function(){   countdown('ban_countdown'); //or elemement}, 1000);

This will make the function countdown execute after 1000 miliseconds.


If you'd like to pass an argument to a function by setTimeout, try this:

setTimeout(countdown, 1000, element);

The syntax of setTimeout is the following:

setTimeout(function,milliseconds,param1,param2,...)