I'm using bootstrap-select and I want to have dependant dropdown. The first is category :
<select class="selectpicker" id="category">
<option value="1"> Fruit </option>
<option value="2"> Animal</option>
</select>
The second is a list of items, the class indicate the category
<select class="selectpicker" id="items">
<option class="1" value="1"> Banana </option>
<option class="1" value="2"> Apple </option>
<option class="2" value="3"> Cat </option>
<option class="2" value="4"> Dog</option>
</select>
My goal is when the user select a filter one or more category it's filter also the items dropdown
This code works for one selection but not for 2. How can I do that ?
<script>
$("#category").change(function () {
var category= $(this).val());
$('option').each(function() {
if ($(this).hasClass(category)) {
$(this).show();
} else {
$(this).hide();
}
});
$('.selectpicker').selectpicker('refresh');
});
</script>