Home > Web Front-end > JS Tutorial > body text

How to Disable and Enable HTML Input Buttons Using JavaScript and jQuery?

Barbara Streisand
Release: 2024-10-30 17:17:25
Original
873 people have browsed it

How to Disable and Enable HTML Input Buttons Using JavaScript and jQuery?

Controlling HTML Input Button State: Disable and Enable

Disabling and enabling HTML input buttons is essential for managing user interactions. Here's how you can achieve this:

Using Javascript

Disable the button:

document.getElementById("Button").disabled = true;
Copy after login

Enable the button:

document.getElementById("Button").disabled = false;
Copy after login

Using jQuery

For jQuery versions prior to 1.6:

Disable the button:

$('#Button').attr('disabled','disabled');
Copy after login

Enable the button:

$('#Button').removeAttr('disabled');
Copy after login

For jQuery versions 1.6 and later:

Disable the button:

$('#Button').prop('disabled', true);
Copy after login

Enable the button:

$('#Button').prop('disabled', false);
Copy after login

By controlling the disabled property, you can toggle the button's state to suit your application's needs.

The above is the detailed content of How to Disable and Enable HTML Input Buttons Using JavaScript and jQuery?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template