Is there anyway to put a .change function into a for loop instead of writing this function out 4 times because i need this same function but with #room_Children1,2,3 and 4 and.room#1,2,3 and 4
$("#room_Children1").change(function () {
switch ($("#room_Children1").val()) {
case "1":
$(".room#1").children().next().next().first().show();
$(".room#1").children().next().next().next().first().hide();
$(".room#1").children().next().last().hide();
break;
case "2":
$(".room#1").children().next().next().first().show();
$(".room#1").children().next().next().next().first().show();
$(".room#1").children().next().last().hide();
break;
case "3":
$(".room#1").children().next().next().first().show();
$(".room#1").children().next().next().next().first().show();
$(".room#1").children().next().last().show();
break;
case "0":
$(".room#1").children().next().next().hide();
break;
default:
alert("You cheated");
break;
}
});
Drop the whole chunk in a function:
Then