I have this need to show and hide a div if a checkbox is checked for multiple checkboxes.
Each div's id that needs to be shown will be the same as the checkboxes name. Is there an easy way to accomplish this without writing a function to handle each checkbox?
$('input[name=checkbox_1]').click(function() {
if ($('input[name=checkbox_1]').is(':checked')) {
$('#checkbox_1').show('slow');
}
else {
$('#checkbox_1').hide('slow');
}
});
$('input[name=checkbox_2]').click(function() {
if ($('input[name=checkbox_2]').is(':checked')) {
$('#checkbox_2').show('slow');
}
else {
$('#checkbox_2').hide('slow');
}
});
});