jQuery | disable/enable an input element
The disable/enable an input element in jQuery can be done by using prop() method. The prop() method is used to set or return properties and values for the selected elements.
Example 1: This example uses prop() method to disable the input text field.
<!DOCTYPE html> <html> <head> <title> JavaScript enable/disable an input element </title> <script src= </script> </head> <body style = "text-align:center;"> <h1 style = "color:green;" > GeeksForGeeks </h1> <input id = "input" type="text" name="input"/> <button onclick="enable_disable()"> Enable/Disable </button> <!-- Script to disable input text area --> <script> function enable_disable() { $("input").prop('disabled', true); } </script> </body> </html> |
chevron_right
filter_none
Output:
- Before clicking the button:

- After clicking the button:

Example 2: This example uses prop() method to enable the input text field.
<!DOCTYPE html> <html> <head> <title> JavaScript enable/disable an input element </title> <script src= </script> </head> <body style = "text-align:center;"> <h1 style = "color:green;" > GeeksForGeeks </h1> <input id = "input" type="text" name="input" disabled/> <button onclick="enable_disable()"> Enable/Disable </button> <!-- Script to enable input text fields --> <script> function enable_disable() { $("input").prop('disabled', false); } </script> </body> </html> |
chevron_right
filter_none
Output:
- Before clicking the button:

- After clicking the button:

Recommended Posts:
- How to enable/disable all input controls inside a form element using jQuery ?
- How to remove parent element except its child element using jQuery ?
- jQuery | :input Selector
- How to use input readonly attribute in jQuery ?
- JQuery | Set the value of an input text field
- How to get the input file size in jQuery ?
- jQuery | Move an element into another element
- JQuery | Set focus on a form input text field on page load
- How to change the element id using jQuery ?
- How to select an element by name with jQuery?
- How to create a div element in jQuery ?
- How to get focused element using jQuery?
- jQuery | element Selector
- jQuery | element + next Selector
- jQuery | Create a div element
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



