Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. 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 button
    document.getElementById("myBtn").disabled = true;

    // Enabling a button
    document.getElementById("myBtn").disabled = false;
    Copied!

    You can also use the querySelector method to select the button and change its disabled property:

    // Disabling a button using querySelector
    document.querySelector('#button').disabled = true;

    // Enabling a button using querySelector
    document.querySelector('#button').disabled = false;
    Copied!

    Event Listener Example

    For a more interactive example, you can disable a button when it is clicked:

    Feedback
  2. 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; …