I am making a form that has various select elements like this
<select class="nace">
<option value="no" selected="selected">No</option>
<option value="yes">Yes</option>
</select>
I am trying to write a jQuery snippet that will change the selection of all these selects of the class “nace”, so the slected values are all in unison. But I am struggling a bit with the functionality.
So far I have an event bound to a the changes on selects but cant quite get it right. Can anyone help me?
$('.nace').change(function() {
var selected = $(this).val();
$('.nace option:selected="selected"' ).each(function(){
$(this+' option[value='+$(this).value+']').attr('selected', 'selected');
});
});
I would have said just this: