+ 1

What code can i use to delay an event in javascript?

I have been working on a project for about 5 days, and wanted to make a button which would give a delay of 2 seconds before triggering the event. I need help, please :(

10th May 2020, 11:22 PM
Teddy Alejandro Moreira VĂ©lez
Teddy Alejandro Moreira VĂ©lez - avatar
2 Answers
+ 3
document.querySelector('button').addEventListener("click",() => setTimeout(yourFunctionName, 2000))
10th May 2020, 11:44 PM
BALU
BALU - avatar
+ 2
Teddy Alejandro Moreira VĂ©lez Hey check this code :)) The alert will be shown after 2 seconds. https://code.sololearn.com/W6GAyRo9TzqO/?ref=app
11th May 2020, 3:10 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar