find(':input'). prop('disabled', false); $('#my_div a'). unbind("click");
Answer: To disable all input elements within div use the following code: $('#message :input'). attr('disabled', true);
To disable all form controls within a fieldset , use the disabled attribute like this <fieldset disabled> . You probably already have some CSS styling that should apply to disabled form controls. This usually also works within a field set without changing anything.
Wrap the input fields and other stuff into a <fieldset> and give it the disabled="disabled" attribute.
Try using the :input
selector, along with a parent selector:
$("#parent-selector :input").attr("disabled", true);
$('#mydiv').find('input, textarea, button, select').attr('disabled','disabled');
For jquery 1.6+, use .prop()
instead of .attr()
,
$("#parent-selector :input").prop("disabled", true);
or
$("#parent-selector :input").attr("disabled", "disabled");
$(document).ready(function () {
$('#chkDisableEnableElements').change(function () {
if ($('#chkDisableEnableElements').is(':checked')) {
enableElements($('#divDifferentElements').children());
}
else {
disableElements($('#divDifferentElements').children());
}
});
});
function disableElements(el) {
for (var i = 0; i < el.length; i++) {
el[i].disabled = true;
disableElements(el[i].children);
}
}
function enableElements(el) {
for (var i = 0; i < el.length; i++) {
el[i].disabled = false;
enableElements(el[i].children);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With