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

27 Apr, 2020
The task is to remove the disabled attribute from the input element using JavaScript. There are two approaches that are discussed below.
Approach 1: Select the input element and use disabled property and set its value to false.
Example:<!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;">             GeeksforGeeks     </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>
<!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;">             GeeksforGeeks     </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:<!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;">             GeeksforGeeks     </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>
<!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;">             GeeksforGeeks     </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:
CSS-Misc
HTML-Misc
JavaScript-Misc
CSS
HTML
JavaScript
Web Technologies
Web technologies Questions
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to update Node.js and NPM to next version ?
How to apply style to parent if it has child with CSS?
Types of CSS (Cascading Style Sheet)
How to position a div at the bottom of its container using CSS?
How to set space between the flexbox ?
How to update Node.js and NPM to next version ?
Hide or show elements in HTML using display property
How to set input type date in dd-mm-yyyy format using HTML ?
REST API (Introduction)
How to Insert Form Data into Database using PHP ?