How to remove disabled attribute using jQuery

Mistake producing Gemini contented Question & Answer :

I person to disable inputs astatine archetypal and past connected click on of a nexus to change them.

This is what I person tried truthful cold, however it doesn’t activity.

HTML:

<enter kind="matter" disabled="disabled" people="inputDisabled" worth=""> 

jQuery:

$("#edit").click on(relation(case){ case.preventDefault(); $('.inputDisabled').removeAttr("disabled") }); 

This exhibits maine actual and past mendacious however thing adjustments for the inputs:

$("#edit").click on(relation(case){ alert(''); case.preventDefault(); alert($('.inputDisabled').attr('disabled')); $('.inputDisabled').removeAttr("disabled"); alert($('.inputDisabled').attr('disabled')); }); 

Ever usage the prop() methodology to change oregon disable parts once utilizing jQuery (seat beneath for wherefore).

Successful your lawsuit, it would beryllium:

$("#edit").click on(relation(case){ case.preventDefault(); $('.inputDisabled').prop("disabled", mendacious); // Component(s) are present enabled. }); 

jsFiddle illustration present.


Wherefore usage prop() once you may usage attr()/removeAttr() to bash this?

Fundamentally, prop() ought to beryllium utilized once getting oregon mounting properties (specified arsenic autoplay, checked, disabled and required amongst others).

Piece what you privation to bash tin technically beryllium accomplished utilizing attr()/removeAttr(), it doesn’t average it ought to beryllium finished - and tin origin unusual/problematic behaviour, arsenic successful this lawsuit.

“The quality betwixt attributes and properties tin beryllium crucial successful circumstantial conditions. Earlier jQuery 1.6, the .attr() technique typically took place values into relationship once retrieving any attributes, which might origin inconsistent behaviour. Arsenic of jQuery 1.6, the .prop() methodology gives a manner to explicitly retrieve place values, piece .attr() retrieves attributes.”

“Properties mostly impact the dynamic government of a DOM component with out altering the serialized HTML property. Examples see the worth place of enter parts, the disabled place of inputs and buttons, oregon the checked place of a checkbox. The .prop() technique ought to beryllium utilized to fit disabled and checked alternatively of the .attr() methodology. The .val() technique ought to beryllium utilized for getting and mounting worth.” - jQuery documentation for prop()

Pre-jQuery three.zero (earlier 2016)

The ground wherefore you ought to usage prop complete removeAttr() is that removeAttr() wholly removes the disabled property itself - arsenic this methodology would merely fit the corresponding place sanction to mendacious:

Anterior to jQuery three.zero, utilizing .removeAttr() connected a boolean property specified arsenic checked, chosen, oregon readonly would besides fit the corresponding named place to mendacious. This behaviour was required for past variations of Net Explorer however is not accurate for contemporary browsers due to the fact that the property represents the first worth and the place represents the actual (dynamic) worth. - jQuery three.zero Breaking Modifications

Piece prop() simply units the place’s underlying boolean worth to mendacious.