I am trying to call a javascript function at the onclick of an html element as shown below. But not sure why the below timeout function is not working here.Any idea
onclick="setTimeout(rating(), 3000)"
I am trying to call a javascript function at the onclick of an html element as shown below. But not sure why the below timeout function is not working here.Any idea
onclick="setTimeout(rating(), 3000)"
remove parenthesis, change:
onclick="setTimeout(rating(), 3000)"
to
onclick="setTimeout(rating, 3000)"
or better way would be:
onclick = setTimeout(function() {
rating();
}, 3000);
onclick="setTimeout(rating, 3000)" // rating without the ()
When you include the parentheses, the function return value is used instead of the function itself.