Reputation: 11
I have this code
$('#sel_kat').change(function() {
$("#" + this.value).show();
});
#sel_kat
is set in CSS to display: none;
. When I select some value inside a <select>
tag, it show me a div
with id
. How can I hide this div when I select another value?
Upvotes: 0
Views: 22
Reputation: 2998
Or you can hide the last item selected
$('#sel_kat').change(function() {
var lastSelect = $('#sel_kat:last').val();
$("#" + lastSelect).hide();
$("#" + this.value).show(); // show selected
});
Upvotes: 0
Reputation: 337743
First, put a common class on all the div
elements related to the select
values. Then you can hide them all before showing the selected one:
$('#sel_kat').change(function() {
$('.sel_div').hide(); // hide all
$("#" + this.value).show(); // show selected
});
Upvotes: 1