Store all #select2
's options in a variable, filter them according to the value of the chosen option in #select1
, and set them using .html()
in #select2
:
var $select1 = $( '#select1' ),
$select2 = $( '#select2' ),
$options = $select2.find( 'option' );
$select1.on('change', function() {
$select2.html($options.filter('[value="' + this.value + '"]'));
}).trigger('change');