<form id="target"> .... </form> 8 Answers
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); 4 Comments
$("#target :input").prop("disabled", true);$(this).closest('form').find('input').prop('disabled', true);. Not sure if you can consolidate that better, I'm still rather noobish at jQuery.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); Comments
With this one line you can disable any input field in a form
$('form *').prop('disabled', true); 2 Comments
You can do it like this:
//HTML BUTTON <button type="button" onclick="disableAll()">Disable</button> //Jquery function function disableAll() { //DISABLE ALL FIELDS THAT ARE NOT DISABLED $('form').find(':input:not(:disabled)').prop('disabled', true); //ENABLE ALL FIELDS THAT DISABLED //$('form').find(':input(:disabled)').prop('disabled', false); } Comments
The definitive answer (covering changes to jQuery api at version 1.6) has been given by Gnarf