I have a select option that, when selected, is supposed to show the appropriate sections. By default everything is set to display:none.
In this instance, if June is selected, then I want it to show all divs that have the class of june.
$('#list').change(function() {
if ($(this).val() == "june") {
$('.june').css('display', 'block')
}
});
The code works as it should. However, I would like to write this more efficiently because I plan on adding additional months. To that end, how would I go about doing something along the lines of this:
$('#list').change(function() {
if ($(this).val() == {
thischosenmonth
}) {
$('.{thischosenmonth}').css('display', 'block')
}
});
where thischosenmonth coincides with the month chosen by the user?
$('.' + $(this).val()).show();inside your change event? Instead of using the IF for each one? If they all had the same class too, likeclass='june month', then you could call$('.month').hide()first to hide all other months that don't apply.