182
rated 0 times
[
189]
[
7]
/ answers: 1 / hits: 29066
/ 12 Years ago, wed, march 21, 2012, 12:00:00
Is it possible to detect if no option was explicitly selected in a select box?
I have tried these methods but none of them works:
<select id=mySelect>
<option value=1>First</option>
<option value=2>Second</option>
<option value=3>Third</option>
<option value=4>Fourth</option>
</select>
Trial 1:
alert($('#select option:selected').length); // returns 1
Trial 2:
alert($('#select option[selected=selected]').length); // returns 1
Trial 3:
alert($('#select option:selected').attr('selected')); // returns 'selected'
Any ideas SO people?
More From » jquery