I have a button that gets triggered by the click of another button. I want to delay click of the second button for 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 didn't work.
No, but your function can set a timer event for whatever delay you want to handle it later.
Conclusion. setTimeout() is a method that will execute a piece of code after the timer has finished running. let timeoutID = setTimeout(function, delay in milliseconds, argument1, argument2,...); The delay is set in milliseconds and 1,000 milliseconds equals 1 second.
To delay a function call, use setTimeout() function. functionname − The function name for the function to be executed. milliseconds − The number of milliseconds. arg1, arg2, arg3 − These are the arguments passed to the function.
To delay a link with inline javascript, just set your href attribute as href="javascript:setTimeout(()=>{window. location = 'URL' },500);" . When you replace the URL with your link, just make sure it is inside the ' ' .
from the docs http://api.jquery.com/delay/
The .delay() method is best for delaying between queued jQuery effects. Because it is limited—it doesn't, for example, offer a way to cancel the delay—.delay() is not a replacement for JavaScript's native setTimeout function, which may be more appropriate for certain use cases.
you can use setTimeout
to bind click handler after a 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);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With