Disabling click event with .delay ()
I have a button that is triggered by clicking another button. I want to delay pressing the second button by two seconds. I used .delay () but it didn't work.
jq(function() {
jq('a.box').click(function() {
jq(this).closest('.button').find('.add_this').delay(2000).click();
})
});
or using setTimeout;
jq(function() {
jq('a.box').click(function() {
setTimeout(function(){
jq(this).closest('.button').find('.add_this').click();
},800);
});
});
But it didn't work.
+3
source to share
1 answer
from the docs http://api.jquery.com/delay/
The .delay () method is best for delaying between jQuery queued after effects. Because it is limited - it does not, for example, offer a way to undo the delay..delay () is not a replacement for the native JavaScript setTimeout, which might be more appropriate for certain use cases.
you can use setTimeout
to bind the click handler after delay
setTimeout(function(){
jq('a.box').closest('.button').find('.add_this').click();
},2000);
EDIT
jq(function() {
jq('a.kklike-box').click(function() {
$this = $(this);
setTimeout(function(){
$this.closest('.deal_buttons').find('.add_this').click();
},800);
});
});
+12
source to share