Javascript Wait 5 Seconds
In this tutorial, we will learn how to use the setTimeout function to create a delay or pause in the execution of a code block. We will also see how to disable a button for a certain amount of time using this function. To disable a button for a certain amount of time such as 5, 10 and 30 sec, we can use the setTimeout function along with the disabled property of the button element. The disabled property is a boolean value that indicates whether the button is disabled or not. To disable a button, we can set its disabled property to true. To enable a button, we can set its disabled property to false.
Thanks for your feedback!
Your contributions will help us to improve service.
Example 1 : Javascript Disable Button For 5 Seconds
In this example, we cover how to disable a JavaScript button for 5 seconds. Upon clicking, the button becomes unclickable or disabled and displays the message 'Wait for 5 seconds...'. After the 5-second delay, the button becomes enabled again
Output of Javascript Disable Button For 5 Seconds
Example 2 : Javascript Disable Button For 30 Seconds
In this example, we will disable the button for 30 seconds using JavaScript's setTimeout function to delay re-enabling the button. Initially, we set the button's disabled property to true. After 30 seconds, we use setTimeout again to set the disabled property to false.
Output of Javascript Disable Button for 30 Seconds
Example 3 : Disable Button for in 10 Seconds by using Javascript
In this Third example of this tutorial, we increase the time for enabling the button, such that we disable the button for 10 seconds upon clicking it, using JavaScript's setTimeout function.