Hey guys, I have a couple bits of code that seem such that they can be compressed, but I'm not sure how to do this.
The code I have is
var checkForUnitReferred = function () {
$("#LeadForm").toggle($("#Claim_UnitReferredNoNull").is(":checked"));
};
checkForUnitReferred();
$("#Claim_UnitReferredNoNull").change(function() {
checkForUnitReferred();
});
It basically checks if the checkbox is checked and displays the form, otherwise it hides it. I would prefer something like this
var checkForUnitReferred = (function() {
$("#LeadForm").toggle($("#Claim_UnitReferredNoNull").is(":checked"));
})();
$("#Claim_UnitReferredNoNull").change(function() {
checkForUnitReferred();
});
I know this doesn't work, but I think something like that would be cleaner. Does anyone know a way to do this?
source
share