Is there a way to detect when the disabled attribute of an input changes in JQuery. I want to toggle the style based on the value.
I can copy/paste the same enable/
Although there are more efficient ways of tackling this problem, one way of handling this is by running a function every xx seconds that will set the required CSS classes on disabled elements:
window.setInterval(1000,function() {
$("input:disabled").addClass("disabled");
$("input:enabled").removeClass("disabled");
});
This will check all input elements every second. But again, this is a VERY bad solution. You would be better off restructuring your code.
Without changing too much of your code and HTML, I would do something like this (didn't test it though):
$("input[name^=Group]").change(function () {
var disabled = ($(this).val() == "No") ? "disabled" : "";
var groupName = $(this).attr("name");
$("#" + groupName + "Fields input")
.attr("disabled", disabled)
.addClass("disabled");
//remove disabled style to all enabled controls
$("input:enabled)").removeClass("disabled");
});