Saturday, December 13, 2025
HomeLanguagesJavascriptHow to remove “disabled” attribute from HTML input element using JavaScript ?

How to remove “disabled” attribute from HTML input element using JavaScript ?

The task is to remove the disabled attribute from the input element using JavaScript. This can be achieved by the following two approaches.

Approach 1: Select the input element and use disabled property and set its value to false.

Example : This example implements the above approach 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        How to remove “disabled” attribute from
        HTML input element using JavaScript ?
    </title>
    <style>
        body {
            text-align: center;
        }
         
        h1 {
            color: green;
        }
    </style>
</head>
 
<body>
    <h1 style="color:green;">
            neveropen
    </h1>
    <p>
        Click on the button to remove disabled attribute
    </p>
    Type:
    <input id="input" disabled />
    <br>
    <br>
    <button onclick="myGFG()">
        Click Here
    </button>
    <p id="gfg">
    </p>
    <script>
        var down = document.getElementById("gfg");
 
        function myGFG() {
            document.getElementById('input').disabled = false;
            down.innerHTML = "Disabled Attribute removed";
        }
    </script>
</body>
 
</html>


Output:

Approach 2: Select the input element and use disabled property and set its value to false. This example selects input element by its class.

Example: This example implements the above approach

html




<!DOCTYPE HTML>
<html>
 
<head>
    <title>
        How to remove “disabled” attribute from
        HTML input element using JavaScript ?
    </title>
    <style>
        body {
            text-align: center;
        }
         
        h1 {
            color: green;
        }
    </style>
</head>
 
<body>
    <h1 style="color:green;">
            neveropen
    </h1>
    <p>
        Click on the button to remove disabled attribute
    </p>
    Type:
    <input id="input" disabled />
    <br>
    <br>
    <button onclick="myGFG()">
        Click Here
    </button>
    <p id="gfg">
    </p>
    <script>
        var down = document.getElementById("gfg");
 
        function myGFG() {
            var input = document.getElementsByClassName('inputClass');
            for (var i = 0; i < input.length; i++) {
                input[i].disabled = false;
            }
            down.innerHTML = "Disabled Attribute removed";
        }
    </script>
</body>
 
</html>


Output:

RELATED ARTICLES

Most Popular

Dominic
32446 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6814 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12030 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7199 POSTS0 COMMENTS
Thapelo Manthata
6896 POSTS0 COMMENTS
Umr Jansen
6882 POSTS0 COMMENTS