I am planning to simplify the process of toggling visibility for 12 different divs when clicking on 12 different buttons. Instead of repeating the same code multiple times, I am considering a more efficient approach.
My idea is to:
Step A) Initially hide all divs
Step B) Use a switch statement to compare with the clicked element and show the corresponding DIV as inline-block
Do you think this would be a good solution?
Please find my current progress on this CodePen link here.
Thanks in advance,
EDIT: I am currently encountering an "unexpected identifier" error on each case statement. Here is the updated code snippet:
$(".klik").click(function(){
$("#oppehoejre").children().css("display","none");
$("#nedrevenstre").children().css("display","none");
var emne = $(this).attr('id');
alert(emne);
switch (emne) {
Case 'klik_multimedia':
$(".multimedia").css("display","inline-block");
break;
Case 'klik_student':
$(".sprogligstudent").css("display","inline-block");
break;
Case 'klik_datamatiker':
$(".datamatiker").css("display","inline-block");
break;
Case 'klik_itdiplom':
$(".itdiplom").css("display","inline-block");
break;
default:
$(".multimedia").css("display","inline-block");
break;
};
});