0

I have wrapped my function call in a setTimeout method like this with for example a 2 second delay. But it is NOT doing anything. It is not causing any delay. What have I wrote wrong?

onclick="setTimeout(MyOriginalFunction('2004', 'Y', 'M', '12'),2000);" 
Bohn
  • 26,091
  • 61
  • 167
  • 254
  • 3
    The argument to `setTimeout` has to be a reference to a function, not a function call itself. – Barmar Jul 05 '18 at 18:42

1 Answers1

0

Try this for passing parameter in setTimeOut function.

function GiveMeCall(name){
alert('Called me '+name);
}
<button onclick="setTimeout(function(){GiveMeCall('Rahul')},2000);" 
 >click me</button>

Please have a look it is getting called. let me know if this is helpful for you. This SetTimeout function only look for reference of the function.

function MyOriginalFunction(){
alert('Called me');
}
<button onclick="setTimeout(MyOriginalFunction,2000);" 
 >click me</button>
Rahul
  • 74
  • 8