Reputation: 55
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
Upvotes: 3
Views: 113
Reputation: 61793
You're close.
setTimeout
call should be inside of your click handler, not below it.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")
};
Upvotes: 3
Reputation: 6191
You are calling showSkills in your button click handler, move your setTimeout line into your click handler instead
$('div.skill').hide();
$('.btn_2').click(function(e){
setTimeout ( showSkills, 3000 );
});
function showSkills(){
alert("Hello")
};
Upvotes: 2
Reputation: 8836
Try this:
$('div.skill').hide();
$('.btn_2').click(function(e){
setTimeout (showSkills, 3000 );
});
function showSkills(){
alert("Hello")
};
Upvotes: 0
Reputation: 1171
$('div.skill').hide();
$('.btn_2').click(function(e){
setTimeout(showSkills, 3000);
});
function showSkills(){
alert("Hello")
};
Upvotes: 0