Javascript remove attribute "disabled" for html input

How can I remove the "disabled" attribute for html input using javascript?

<input id=edit disabled> 

at onclick I wanted my input tag to not consist of the "disabled" attribute.

+42
javascript input attributes
Jul 30 2018-12-12T00:
source share
4 answers

Set the element disabled property to false:

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

If you use jQuery, the equivalent will look like this:

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

For several input fields, you can access them by class:

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

Where document can be replaced with a form, for example, to find only elements inside this form. You can also use getElementsByTagName('input') to get all input elements. In your for iteration, you will need to check that inputs[i].type == 'text' .

+104
Jul 30 '12 at 10:50
source share

Why not just remove this attribute?

  • vanilla JS: elem.removeAttribute('disabled')
  • jQuery: elem.removeAttr('disabled')
+13
Mar 31 '15 at 13:40
source share

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

 document.myForm.myInputName.disabled = false; 
+2
Jun 08 '13 at 13:19
source share
 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> 

the code of the previous answers does not seem to work in native mode, but there is a workaround: method 3.

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

0
Sep 18 '16 at 13:19
source share



All Articles