How to disable all <input > inside a form with jQuery?
<form id="target">
....
</form>
In older versions you could use attr
. As of jQuery 1.6 you should use prop
instead:
$("#target :input").prop("disabled", true);
To disable all form elements inside 'target'. See :input
:
Matches all input, textarea, select and button elements.
If you only want the <input>
elements:
$("#target input").prop("disabled", true);
Above example is technically incorrect. Per latest jQuery, use the prop()
method should be used for things like disabled. See their API page.
To disable all form elements inside 'target', use the :input selector which matches all input, textarea, select and button elements.
$("#target :input").prop("disabled", true);
If you only want the elements, use this.
$("#target input").prop("disabled", true);
Also the more concise way is to use their selectors engine. So to disable all form elements in a div or form parent.
$myForm.find(':input:not(:disabled)').prop('disabled',true)
you can add
<fieldset class="fieldset">
and then you can call
$('.fieldset').prop('disabled', true);