0

How to disable and enable input field with jQuery?

in jQuery 1.6+ use .prop() function

.prop() function is a convenient way to set the value of properties, in this case, 'disabled' is a chosen attribute that should be modified.

$('#disableInput').click(function() {
  	$('input').prop('disabled', true);
});

$('#enableInput').click(function() {
  	$('input').prop('disabled', false);
});
<input type="text" value="test"/>
<button id="disableInput">Disable</button>
<button id="enableInput">Enable</button>
RUN
in jQuery 1.5 and below use .attr() function
$('#disableInput').click(function() {
  	$('input').attr('disabled', true);
});

$('#enableInput').click(function() {
  	$('input').attr('disabled', false);
});
<input type="text" value="test"/>
<button id="disableInput">Disable</button>
<button id="enableInput">Enable</button>
RUN
add comment
Suggest a different solution or add another example