Elements in your form that are not valid should be disabled. A disabled element is usually shown dimmed-out with gray text. A disabled element can't be focused, doesn't respond to the user, and won't be sent when the form is submitted.
The odd thing about the disabled attribute is that its presence inside of an element disables it. It doesn't need to be set to true
or false
. In fact, setting it true
or false
has no effect. To disable the element, add the disabled attribute. To enable the element, remove the disabled attribute. Luckily, jQuery understands this odd behavior and takes care of this detail for us.
We can use the jQuery .prop()
method to help us out. When we want to disable the element, we do the following:
$('#someId).prop('disabled', true);
And when we want to enable the element, we do the following:
$('#someId).prop('disabled', false);
In spite of the way things look, jQuery will do exactly what we said. The first line of code will add the disabled...