I want to disable by default the inputs, and i have a check box that allows to enable them;
so my code of the checkbox is :
function toggleStatus() {
if ($('#toggleElement').is(':checked')) {
$('#elementsToOperateOn :input').attr('disabled', true);
}
else {
$('#elementsToOperateOn :input').removeAttr('disabled');
}
}
and it’s called in an input with onchange="toggleStatus()"; but the default status of the inputs are enabled and i don’t want to add disabled=”disabled” to each input, how can i do it with jquery? and how can i make it work with the existing onchange?
Disable the inputs when the DOM is ready.
O.K. After your update, the answer is even simpler, just trigger the
onchangeevent:Either with:
or with