There is an Input Element which is disabled, the task is to enable it using JQuery. Here are a few examples discussed.
To understand example first few methods to know.
JQuery prop() method
This method set/return properties and values of selected elements.
If we use this method to return the property value, it will return the value of the FIRST selected element.
If we use this method to set property values, it will set one or more than one property/value pairs for set of selected elements.
Syntax:
-
Return the value of property:
$(selector).prop(property)
-
Set the property and value:
$(selector).prop(property, value)
-
Set the property and value using function:
$(selector).prop(property, function(index, currentValue))
-
Set multiple property and values:
$(selector).prop({property:value, property:value, ...})
JQuery removeAttr() method
This method removes one or more than one attributes from the matched elements.
Syntax:
$(selector).removeAttr(attribute)
Parameters:
- attribute:This parameter is required. It specifies one or more than one attributes to remove. If want to remove several attributes, Use a space among the attribute names.
Example-1:In this example the input element is enabled by prop() method by setting the disabled property to false.
<!DOCTYPE HTML> <html> <head> <title> JQuery | Remove “disabled” attribute. </title> <script src = </script> </head> <body style = "text-align: center;"> <h1 style = "color: green;" > GeeksForGeeks </h1> Input Box: <input type = "text" disabled = "disabled" class = "Disable" value = ""/> <br> <br> <button id = "enable"> click to Enable </button> <script> $("#enable").click(function(event) { event.preventDefault(); $('.Disable').prop("disabled", false); }); </script> </body> </html> |
Output:
-
Before clicking on the button:
-
After clicking on the button:
Example-2:In this example the input element is enabled by removeAttr() method by removing the disabled property.
<!DOCTYPE HTML> <html> <head> <title> JQuery | Remove “disabled” attribute. </title> <script src = </script> </head> <body style = "text-align: center;"> <h1 style = "color: green;" > GeeksForGeeks </h1> Input Box: <input type = "text" disabled = "disabled" class = "Disable" value = ""/> <br> <br> <button id = "enable"> click to Enable </button> <script> $("#enable").click(function(event) { event.preventDefault(); $('.Disable').removeAttr("disabled") }); </script> </body> </html> |
Output:
-
Before clicking on the button:
-
After clicking on the button:
Recommended Posts:
- How to remove “disabled” attribute from HTML input element using JavaScript ?
- How to remove CSS “top” and “left” attribute with jQuery ?
- How to remove parent element except its child element using jQuery ?
- How to change the src attribute of an img element in JavaScript / jQuery ?
- How to remove options from select element using jQuery ?
- How to set attribute without value using jQuery ?
- jQuery | remove()
- JavaScript | Remove a JSON attribute
- How to fadeOut and remove a div using jQuery ?
- How to use input readonly attribute in jQuery ?
- How to remove specific value from array using jQuery ?
- How to Remove an Event Handler using jQuery ?
- How to Add and Remove multiple classes in jQuery ?
- How to Dynamically Add/Remove Table Rows using jQuery ?
- How to remove all inline styles using JavaScript/jQuery ?
- How to Display/Hide functions using aria-hidden attribute in jQuery ?
- jQuery | Move an element into another element
- How to get an element by its href attribute ?
- How to change the element id using jQuery ?
- How to get a DOM Element from a jQuery Selector ?
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.


