On a web page, if you select different options on the first drop-down, different options will appear in the second drop-down.
You could try like this.
First hide all the options and show only matching options using toggleClass()
$(function() {
$('#independent').on('change', function (e) {
$('#dependent').val('');
var endingChar = $(this).val().split('').pop();
var selected = $( '#independent' ).val();
$('#dependent option').addClass('show');
$('#dependent option[value^='+selected+']').toggleClass('show');
})
});
.show{
display:none;
}