javascript remove "disabled" attribute from html input

JavascriptInputAttributes

Javascript Problem Overview


How can I remove the "disabled" attribute from an HTML input using javascript?

<input id="edit" disabled>

at onClick I want my input tag to not consist of "disabled" attribute.

Javascript Solutions


Solution 1 - Javascript

Set the element's disabled property to false:

document.getElementById('my-input-id').disabled = false;

If you're using jQuery, the equivalent would be:

$('#my-input-id').prop('disabled', false);

For several input fields, you may access them by class instead:

var inputs = document.getElementsByClassName('my-input-class');
for(var i = 0; i < inputs.length; i++) {
    inputs[i].disabled = false;
}

Where document could be replaced with a form, for instance, to find only the elements inside that form. You could also use getElementsByTagName('input') to get all input elements. In your for iteration, you'd then have to check that inputs[i].type == 'text'.

Solution 2 - Javascript

Why not just remove that attribute?

  1. vanilla JS: elem.removeAttribute('disabled')
  2. jQuery: elem.removeAttr('disabled')

Solution 3 - Javascript

Best answer is just removeAttribute

element.removeAttribute("disabled");

Solution 4 - Javascript

To set the disabled to false using the name property of the input:

document.myForm.myInputName.disabled = false;

Solution 5 - Javascript

$("#input-id").attr("disabled", false)

Solution 6 - Javascript

method 1 <input type="text" onclick="this.disabled=false;" disabled>
<hr>
method 2 <input type="text" onclick="this.removeAttribute('disabled');" disabled>
<hr>
method 3 <input type="text" onclick="this.removeAttribute('readonly');" readonly>

code of the previous answers don't seem to work in inline mode, but there is a workaround: method 3.

see demo https://jsfiddle.net/eliz82/xqzccdfg/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSam SanView Question on Stackoverflow
Solution 1 - JavascriptDavid HedlundView Answer on Stackoverflow
Solution 2 - JavascriptDragos RusuView Answer on Stackoverflow
Solution 3 - JavascriptHarshit NigamView Answer on Stackoverflow
Solution 4 - JavascriptHenry HeddenView Answer on Stackoverflow
Solution 5 - JavascriptSilverio Dos SantosView Answer on Stackoverflow
Solution 6 - Javascriptcrisc2000View Answer on Stackoverflow