How can I make a button to be auto click using setTimeout in JAVASCRIPT? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I make a button to be auto click using setTimeout in JAVASCRIPT?

I want to make a button to be auto clicked after a particular period. I have not any idea to perform the task. Please tell me how can I do?

24th Mar 2021, 12:33 PM
Coder-Rohit[{(∞)}]
Coder-Rohit[{(∞)}] - avatar
1 Answer
+ 1
setTimeout(() => button.click(),delay); where 'button' should hold a reference to the targeted <button> element and delay is the time in millisecond after when the callback function will be called... reference to html element (in the DOM) could be retrieved from many ways, among wich getElementById or querySelector ;)
24th Mar 2021, 1:36 PM
visph
visph - avatar