Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

jquery
disable
button

How to make a jQuery disable button

Educative Answers Team

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.

svg viewer

Library

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">

Code

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);

RELATED TAGS

jquery
disable
button
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring