What code can i use to delay an event in javascript? | SoloLearn: Learn to code for FREE!

+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 :(

5/10/2020 11:22:02 PM

Teddy Alejandro Moreira Vélez

2 Answers

New Answer

+3

document.querySelector('button').addEventListener("click",() => setTimeout(yourFunctionName, 2000))

+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