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 of ββthis code is to choose the first option.
After 1.10, the $('#s1').val(''); stops working the same way. I suppose it was never intended to be used that way, but its old code and somehow had to be upgraded ...
After jQuery 1.10, nothing is selected, and $('#s1').val() returns null .
Change code to:
$('#s1 option[value=1]').hide(); $('#s1').val($('#s1 option').first().val());
Does work with new and old versions of jQuery work.
My question is, is there a shorter / more elegant way to do the same?
javascript jquery
bbonev
source share