- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
In JavaScript, you can disable a button by setting its disabled property to true. This makes the button unclickable and usually renders it in gray, indicating that it is inactive. Conversely, you can enable a button by setting the disabled property to false.
Example Code
Here is a simple example demonstrating how to disable and enable a button using JavaScript:
// Disabling a buttondocument.getElementById("myBtn").disabled = true;// Enabling a buttondocument.getElementById("myBtn").disabled = false;Copied!✕CopyYou can also use the querySelector method to select the button and change its disabled property:
// Disabling a button using querySelectordocument.querySelector('#button').disabled = true;// Enabling a button using querySelectordocument.querySelector('#button').disabled = false;Copied!✕CopyEvent Listener Example
For a more interactive example, you can disable a button when it is clicked:
HTML DOM Button disabled Property - W3Schools
Description The disabled property sets or returns whether a button is disabled, or not. A disabled element is unusable and un-clickable. Disabled elements are usually rendered in gray by default in …
See results only from w3schools.comTry It Yourself
The W3Schools online code editor allows you to edit code and view the result in …
Tryit Editor V3.7
The W3Schools online code editor allows you to edit code and view the result in …
Enable/disable a button in pure javascript - Stack Overflow
Now, when working with DOM objects in JavaScript, there are two ways to affect the current state of an element and it's important to understand the effects of working with these two techniques:
- Reviews: 2
JavaScript- Disable and Enable Button in JS - GeeksforGeeks
Nov 28, 2024 · Disabling buttons in JavaScript provides a flexible way to control user interaction and enhance web applications. Whether it's a simple toggle, a dynamic state change, or form-based …
Disable a HTML Button in JavaScript [With Examples]
Jul 16, 2024 · How to disable a button using only JavaScript. Tutorial for beginners. Examples included
HTMLButtonElement: disabled property - Web APIs | MDN
Apr 7, 2023 · The HTMLButtonElement.disabled property indicates whether the control is disabled, meaning that it does not accept any clicks.
How to Enable/Disable an HTML Button Based on Scenarios: A …
Nov 27, 2025 · Enabling or disabling buttons *contextually*—based on user actions, form validity, data loading states, or user roles—ensures smoother, safer, and more intuitive interactions. In this guide, …
How to Enable/Disable Input Button Using JavaScript
Mar 11, 2025 · This tutorial will guide you through the steps of enabling and disabling an HTML input button using JavaScript and jQuery. By the end, you’ll be …
How to disable a button in JavaScript - JS.ORG
Nov 26, 2022 · To disable a button in JavaScript, you can use the disabled` attribute. Here's an example of how to do it: This code will get the button with the id myButton, and then set the disabled attribute …
How to Disable a Button Conditionally in JavaScript?
Aug 5, 2025 · In JavaScript, you can conditionally disable buttons based on specific criteria to control user interactions. Using simple if-else statements or event …
How to disable a button in JavaScript - CoreUI
Jan 19, 2024 · Let’s delve into the art of disabling a button in JavaScript, guiding you through a variety of methods with intuitive code examples—and don’t worry; …