The following behaves differently between jQuery 1.9 and 1.10+:
<select id="s1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
$('#s1 option[value=1]').hide();
$('#s1').val('');
The idea behind this code is to select the first option.
After 1.10, the $('#s1').val('');
part is no longer working in the same way. I suppose that it was never meant to be used that way but its old code and have to be modernized in some way...
After jQuery 1.10 nothing is selected and $('#s1').val()
returns null
.
Changing code to:
$('#s1 option[value=1]').hide();
$('#s1').val($('#s1 option').first().val());
Does the job with both new and old jQuery versions.
My question is if there is shorter/more elegant way to do the same thing?