Saturday, October 25, 2025
HomeLanguagesJavascriptHow to disable button element dynamically using JavaScript ?

How to disable button element dynamically using JavaScript ?

The Button disabled property in HTML DOM is used to set or return whether a Button element would be disabled or not. A disabled element is un-clickable and unusable. It contains a boolean value.

Syntax: It is used to set the button disabled property.

buttonObject.disabled = "value"

Example: In this example, we will disable a button using the disabled attribute.

HTML




<body style="text-align:center">
  
    <h1 style="color: green;">
        neveropen
    </h1>
  
    <h2>
        How to disable button element<br>
        dynamically using JavaScript?
    </h2>
  
    <!-- Assigning id to Button. -->
    <button id="GFG" onclick="Geeks()">
        Submit
    </button>
  
    <br><br>
  
    <p id="sudo"></p>
  
    <script>
        function Geeks() {
          
            document.getElementById("GFG")
                .disabled = "true";
          
            document.getElementById("sudo")
                .innerHTML = "Button is Disabled";
        } 
    </script>
</body>


Output:

Disable button element dynamically

Disable button element dynamically

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS