jQuery is a lightweight JavaScript library that has simplified client-side webpage development by adopting a “write less, do more” ideology.
Sometimes, clicking a button twice ends up submitting the form more than once, which creates a problem. Luckily, it is possible with jQuery to disable the button after the first click.
To use the disable button feature, you need to import this library:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
In the code below, two buttons are created with the <input>
tag. One of the buttons is disabled after the first click, and the other one works as a normal button. In JavaScript, the “disable” attribute is added to the specific button:
$("#btn").attr("disabled", true);
Free Resources