For example, let's say you have 8 sections to hide/show and depending on the value of a dropdown, you have to show or hide dynamically from 1 to 8 sections.
1) Is there any better way of doing this than with the approach of the code below?
2) Is this approach acceptable?
$("#dropdown").change(function(){
var value = this.value;
var $section1 = $("#section1");
var $section2 = $("#section2");
var $section3 = $("#section3");
$(".section").hide(); //hides all sections
if(value == "someValue"){
$section1.show();
$section2.show();
} else if (value == "someOtherValue") {
$section3.show();
} else {
$section2.show();
$section3.show();
}
//etc
})
Any other advice that you consider helpful will be appreciated.