I am looking to refactor the three lines of code in the else part of the conditional, you'll see where I have it commented.
You'll notice a naming convention for the id's: id, id-div, as seen in the first line: club-community-service, club-community-service-id
I want to shorten that up. I thought maybe storing all names into an array, then looping thru them like (below). If there is a better way to go about this, I am all ears, thanks!
//in theory
array names = [names...];
foreach(names as n) {
$("#" + n + "-div").toggle($("#" + n).get(0).checked);
}
$('#high-school-student').bind('click', function() {
if($("input[id=high-school-student]").is(":checked")) {
$('.field.full.club-community-service, .field.full.other-campus-activities, .field.full.community-public-service, .field.full.other-community-event-activity, .field.honors-program, .field.full.out-of-hs-5-years').hide();
$('#club-community-service-div, #other-campus-activities-div, #community-public-service-div, #other-community-event-activity-div').hide();
} else {
$('.field.full.club-community-service, .field.full.other-campus-activities, .field.full.community-public-service, .field.full.other-community-event-activity, .field.honors-program, .field.full.out-of-hs-5-years').show();
// ------ RIGHT HERE - best way to refactor these next three lines
$("#club-community-service-div").toggle($('#club-community-service').get(0).checked);
$("#other-campus-activities-div").toggle($('#other-campus-activities').get(0).checked);
$("#community-public-service-div").toggle($('#community-public-service').get(0).checked);
}
});
$('.watch-for-toggle').bind('click', function() {
var id = $(this).attr('id');
$('#' + id + '-div').toggle();
});