Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setTimeout issue, there is no time out

sorry, but this isn't easy for me....! I want a div to show after several seconds,after a click on a button. It is showing, but right when you click, there is no delay. What am i doing wrong here?

$('div.skill').hide();
$('.btn_2').click(function(e){              
        showSkills ();
      });
function showSkills(){
    alert("Hello")
};
setTimeout ( "showSkills()", 3000 );

Tnx

like image 333
esther Avatar asked Nov 25 '25 16:11

esther


1 Answers

You're close.

  1. The setTimeout call should be inside of your click handler, not below it.
  2. There is no need to pass the function name as a string.

This is the proper way to achieve what you're after:

$('div.skill').hide();
$('.btn_2').click(function (e) {
    setTimeout(showSkills, 3000);
});

function showSkills() {
    alert("Hello")
};
like image 159
James Hill Avatar answered Nov 28 '25 07:11

James Hill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!